Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Database Searcher
Author:
Metaferia
E-mail:
Click to e-mail author
Submitted:
10/30/2006
Version:
VB 2005
Compatibility:
VB 2005
Category:
Databases
Views:
64464
This code will search into the database for the text you wrote and show the result in the datagrid view. it's very usefull you have to check it.
Declarations:
instert a button named utOk, a text box named txtName and a datagrid named Datagrid1. enjoy and put this code under the button code
Code:
Private Sub butOk_Click(ByValsender As System.Object, ByVal e As System.EventArgs) Handles but_ok.Click Dim strConnection As String = "Data Source=your SQL data source;Initial Catalog=your database; Integrated Security=True" Dim cn As SqlClient.SqlConnection = New SqlClient.SqlConnection(strConnection) Dim ds As New DataSet Dim strSelect As String 'strSelect As String strSelect = "SELECT * FROM " & YourTable & " WHERE [Search Field] = '" & Me.txtName.Text & "'" Dim dscmd As New SqlClient.SqlDataAdapter(strSelect, cn) dscmd.Fill(ds, "your table") Me.Datagrid1.DataSource = ds Me.Datagrid1.DataMember = "your table" Dim con As Integer con = Me.BindingContext(ds, "your table").Count If con = 0 Then MessageBox.Show("Recourd could not be found") End If End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement