Hello all,
I need to capture multiple Key values from a SQL Database and I'm having trouble getting the code right.
I have a field value that can be found in multiple rows from the database. For instance a developer can write a program and that program name will be assigned to multiple clients. I'm trying to perform a search for that program name and return all the Client ID's it is assigned to.
I tried using a loop and it keeps failing. The only code I can get to work through trial and error is below and it only returns one Client ID. I hate to ask for actual code but does anyone know an easy way to capture the ID's?
I need to capture multiple Key values from a SQL Database and I'm having trouble getting the code right.
I have a field value that can be found in multiple rows from the database. For instance a developer can write a program and that program name will be assigned to multiple clients. I'm trying to perform a search for that program name and return all the Client ID's it is assigned to.
I tried using a loop and it keeps failing. The only code I can get to work through trial and error is below and it only returns one Client ID. I hate to ask for actual code but does anyone know an easy way to capture the ID's?
Code:
Try
MySQLconnection = New SqlConnection(Myconstring)
MySQLconnection.Open()
mySQLCom = "Select Client_ID from XXXXX.Table where Program_name='" + ProgName + "'"
MySQLcommand = New SqlCommand(mySQLCom, MySQLconnection)
If ConnectionState.Open Then
MySQLreader = MySQLcommand.ExecuteReader()
End If
Catch ex As SqlException
MessageBox.Show("Error while Reading a record from the XXXXX.Table - " & ex.Message, "Read Table")
End Try
If MySQLreader.HasRows Then
MySQLreader.Read()
' The client_id of the database read is a BigInt
AcceptData = MySQLreader.GetInt64(0)
ReadData = Convert.ToString(AcceptData)
ART2CSDfrm.InformationTxb.AppendText(Environment.NewLine & "Request : " + ReadData + " Found for " + "Program: " + ProgName + vbCr)
ReturnData = "Success"
Else
ReadData = "No Rows Found"
End If