Discussion Locked

Search

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Using a windows form in VS.net I am trying to create a form where the user can input the name of the person he or she is searching for and the DB would return all the fields in that record.

I can easily set up the fields but what do I need to putin so the table does not fill itself with all the names in the DB (over 200 000)

Do I use wild characters or is there a SQL or T-SQL format to use for searching SQL 2000?

Thanks in advance for any help.

Albert

1 reply

by ahsan umair

The task is fairly easy to accomplish.
you can use SQLCommand Object To Execute an sql statement that will return the only record that match exactly with your given criteria. Here is the code to give some idea.

---------------------------------------------
Dim mySelectQuery As String = "SELECT * FROM Users Where UserName = '" & txtUser.Text & "'"
Dim myConnection As New SqlConnection(myConnString)
Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As SqlDataReader
myReader = myCommand.ExecuteReader()
' Always call Read before accessing data.
While myReader.Read()
txtUserID.text = myReader.GetInt32(0)txtUserName.text = myReader.GetString(1)
'and so on.....
End While
myReader.Close()
' Close the connection when done with it.
myConnection.Close()

------------------------------------------------
Hope this will help :)
Ahsan Umair.

This discussion is closed to new replies.