这是我的代码,任何帮助将不胜感激。 一旦我在txtbarcode.text上输入productid,如果它存在于我的数据库中,它应该填充我的txtitemdesc.textbox。
Protected Sub txtbarcode_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtbarcode.TextChanged
Dim con As SqlConnection = New SqlConnection("Data Source = pc11-pc\kim; Initial Catalog = convertpos; User Id = sa; Password = 123")
con.Open()
Dim sqlstr As String = ("Select * from Product where ProductID = @ProductID")
Dim cmd As SqlCommand = New SqlCommand(sqlstr, con)
cmd.Parameters.AddWithValue("@ProductID", txtbarcode.Text)
Dim reader As SqlDataReader = cmd.ExecuteReader()
If reader.HasRows Then
reader.Read()
txtitemdesc.Text = reader("ProductName").ToString()
MsgBox(reader("ProductName").ToString())
End If
con.Close()
End Sub