我正在尝试将数据添加到MySQL Server数据库。
以下是代码:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connection As SqlConnection = New SqlConnection("Data Source=192.168.3.173\hidp;Initial Catalog=HIDP;Persist Security Info=True;User ID=intranet;Password=kikapu;APP=Intranet")
Dim sql As String = "Insert into [RAVARIAS].[StockMovimentos] ([CodHospital], [utilizador], [servico], [CodDevice], [CodConsumivel], [TipoMovimento], [DtMovimento], [Qtd]) values (@CodHospital, @utilizador, @servico, @CodDevice, @CodConsumivel, @TipoMovimento, @DtMovimento, @Qtd)"
Dim cmd As SqlCommand = New SqlCommand(sql, connection)
cmd.Parameters.AddWithValue("@CodHospital", Session("Codhospital"))
cmd.Parameters.AddWithValue("@utilizador", TextBox1.Text)
cmd.Parameters.AddWithValue("@servico", TextBox2.Text)
cmd.Parameters.AddWithValue("@CodDevice", DropDownList3.SelectedItem)
cmd.Parameters.AddWithValue("@CodConsumivel", DropDownList4.SelectedItem)
cmd.Parameters.AddWithValue("@TipoMovimento", DropDownList2.SelectedItem)
cmd.Parameters.AddWithValue("@DtMovimento", Calendar1.SelectedDate)
cmd.Parameters.AddWithValue("@Qtd", TextBox4.Text)
connection.Open()
cmd.ExecuteNonQuery()
connection.Close()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox4.Text = ""
DropDownList2.ClearSelection()
DropDownList3.ClearSelection()
DropDownList4.ClearSelection()
Calendar1.SelectedDates.Clear()
End Sub
当我点击按钮时没有任何反应。