Hello buddies im new in visual basic so please tell me i have connected a database sql server with VB6 i want to know what is code of to search data like if im searching a name just like James in text field there record will searched so what is the code of it and same like in datagrid please help me
Please help me
Collapse
X
-
Originally posted by hussainiHello buddies im new in visual basic so please tell me i have connected a database sql server with VB6 i want to know what is code of to search data like if im searching a name just like James in text field there record will searched so what is the code of it and same like in datagrid please help me
Code:Dim cn As ADODB.Connection Set cn = New ADODB.Connection With cn .Provider = "SQLOLEDB" .Properties("Data Source") = "name of your sql server" .Properties("User ID") = "your user id" .Properties("Password") = "your password" .Open .DefaultDatabase = "your database name" End With
Code:Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset With rs .ActiveConnection = cn .CursorType = adOpenStatic .CursorLocation = adUseClient .LockType = adLockOptimistic End With
Code:Dim stSQL As String stSQL = "SELECT * FROM [Your Database Name] WHERE [Your Field Name] = '" & YourSearchCriteria & "'" rs.Source = stSQL rs.Open
-
Originally posted by willakawillHi. First you will need to open a connection to sql server with a connection object:
Code:Dim cn As ADODB.Connection Set cn = New ADODB.Connection With cn .Provider = "SQLOLEDB" .Properties("Data Source") = "name of your sql server" .Properties("User ID") = "your user id" .Properties("Password") = "your password" .Open .DefaultDatabase = "your database name" End With
Code:Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset With rs .ActiveConnection = cn .CursorType = adOpenStatic .CursorLocation = adUseClient .LockType = adLockOptimistic End With
Code:Dim stSQL As String stSQL = "SELECT * FROM [Your Database Name] WHERE [Your Field Name] = '" & YourSearchCriteria & "'" rs.Source = stSQL rs.Open
Comment
-
Originally posted by hussainiwell i dont understand ..... 1st of i have make connection then where is search code
What do you mean by you don't understand? Isn't the below code segment looks like "search code" that you have been looking for? Please take some time to learn things on your own too, here at TheScripts we help people to solve their coding problem & not providing full working application as per their need. Good luck & Take care.
Code:Dim stSQL As String stSQL = "SELECT * FROM [Your Table Name] WHERE [Your Field Name] = '" & YourSearchCriteria & "'" rs.Source = stSQL rs.Open
Comment
-
You don't have a chance at getting this to work with your approach. There is far too much to learn. There are, however, plenty of pundits who scroll through these questions looking for opportunities to show how much they know so you may be lucky and someone will complete your project for you.
I recommend that you get a book and use the above code to assist you in learning what you need to learn.
Good luckComment
Comment