Dim cn As SqlConnection
Dim strCnn As String = "Your data base connection string"
cn = New SqlConnection(strCnn)
Dim comm As New SqlCommand("SELECT ItEquipmentNo FROM tblITEquipmentName WHERE equipmentName LIKE '" & it & "%'", cn)
'' If ur using Sp then Commandtype= CommandType.StoredProcedure if it is Text then comm.CommandType=CommandType.Text
comm.CommandType = CommandType.Text
Dim ds As SqlDataReader
ds = comm.ExecuteScalar
If ds.HasRows Then
' do what u want here using the data
Dim x As String = ds.Item("columnname")
''Close your connections and commands.
Catch ex As Exception
''Handle error if any
I've tried your code.,but when the i click the button,.the messagebox pop without the value of equipmentNameID
Dim it As String = "Mouse"
Dim strQueryITName As String = "SELECT equipmentNameID FROM tblITEquipmentName WHERE equipmentName LIKE '" & it & "%'"
Dim cmdQueryITName As OleDbCommand = New OleDbCommand(strQueryITName, myConnection)
Dim queryITNameReader As OleDbDataReader
cmdQueryITName.CommandType = CommandType.Text
queryITNameReader = cmdQueryITName.ExecuteReader
If queryITNameReader.HasRows Then
Dim it2 As String = queryITNameReader.Item("equipmentNameID")
When ur debugging the code are you getting anything into it2? And which database are u using? i dont think ur using SQL, i guess its Access database.. please check if the Query is correct and also u have data in database for that select statement
the it2 doesn't return anything. Yes, I'm using Access for my database. And my query is correct, because i've tried to put a message box in between the while statement. By the way, the equipmentNameID column is the primary key.
Dim strQ As String = "SELECT * FROM tblITEquipmentName WHERE equipmentName = 'Mouse'"
Dim cmdQ As OleDbCommand = New OleDbCommand(strQ, myConnection)
Dim QReader As OleDbDataReader
Dim it As String
QReader = cmdQ.ExecuteReader
If QReader.HasRows Then
it = QReader.Item("equipmentNameID")