Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
hi. any one tell me how find records by name in database? im using vb.net and sql searver. thanks
Posted
Comments
Rajeev Jayaram 12-Feb-12 12:44pm    
What have you tried until now?
Varun Sareen 12-Feb-12 23:21pm    
What have you tried and where you are facing the problem. Also do you want full code or just the query part?

1 solution

Sample code layout:
VB
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Try
con.ConnectionString = "Data Source=atisource;Initial Catalog=BillingSys;Persist Security Info=True;User ID=sa;Password=12345678"
con.Open()
cmd.Connection = con
cmd.CommandText = "SELECT [field1], [field2] FROM [tablename] WHERE [condition] ORDER BY [sortfield]"
Dim lrd As SqlDataReader = cmd.ExecuteReader()

While lrd.Read()
'Do something here
End While

Catch ex As Exception
MessageBox.Show("Error while retrieving records on table..." & ex.Message, "Load Records")
Finally
con.Close()
End Try
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900