Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Dim objConnection As SqlConnection = New SqlConnection("Data Source=localhost;Initial Catalog=Northwind;User Id=sa;Password=sasasa;")
Dim objCommand As SqlCommand = New SqlCommand
Dim strSQL As String
Dim _customerID, _companyName As String
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Try
objConnection.Open()
strSQL = " select * from Customers where customerID = '" & txtCustomerID.Text & "' "
objCommand.Connection = objConnection
objCommand.CommandText() = strSQL
Dim _dr As SqlDataReader = objCommand.ExecuteReader
If _dr.Read = False Then
MsgBox("CustomerID is not found", MsgBoxStyle.Critical, "Message")
txtCustomerID.Clear()
txtCompanyName.Clear()
txtCustomerID.Focus()
Else
_customerID = _dr.GetValue(0)
_companyName = _dr.GetValue(1)
MsgBox(" CustomerID : " + _customerID + vbCrLf + "CompanyName : " + _companyName, MsgBoxStyle.OKOnly, "Message")
End If
Catch ex As Exception
MsgBox("Error has found : " + ex.Message.ToString, MsgBoxStyle.Critical, "Message")
Finally
objConnection.Close()
End Try
End Sub
End Sub