Click here to Skip to main content
16,022,752 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Simple search using gridview with vb.net mysql.

When we enter the value in the text box and submit with the help of button how can we form the query and fetch records to the gridview.

Thanks in Advance
Posted

Please elaborate the desired output you want..
Q1 : The SQl query which pass your entered text as parameter ?
Q2 : How to fill the gridview with the output of your SQL statement?
 
Share this answer
 
Comments
Member 8576082 18-Jan-12 1:53am    
for example, mysql table has name,age,id,phone,address 5 fields respectively. name is my input, so i've to use name as text box and then click button then i've store the text box value into a variable and then form a query then fill a gridview. I dint have any idea about gridview.
Hi,

1.Drag and drop a gridview in your aspx page/form.
2.Give id to your gridview.
3.Build a select query and use sql adapter to get the dataset from the backend.
Then bind it as datasource to your grid view.

Here is a example

VB
Public Class Form1
'Declare the string variable 'connectionString' to hold the ConnectionString
Dim connectionString As String = "server=SYS2;" + "integrated security=SSPI;" +
 "database=FinAccounting"
'Declare the string variable 'str_Account_Select' to hold the SQL statement
Dim str_Account_Select As String = "SELECT * FROM AccountsTable "

Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim myAdapter As SqlDataAdapter
'Declare the DataSet object
Dim myDataSet As DataSet

Private Sub LoadData()

    'Instantiate the Connection object
    myConnection = New SqlConnection(connectionString)

    'Instantiate the Command object
    myCommand = New SqlCommand(str_Account_Select, myConnection)

    myConnection.Open()

    'Instantiate  DataSet object
    myDataSet = New DataSet()

    'Instantiate  DataAdapter object
    myAdapter = New SqlDataAdapter()

    'Set DataAdapter command properties
    myAdapter.SelectCommand = myCommand

    'Populate the Dataset
    myAdapter.Fill(myDataSet, "AccountsTable")

    If (myDataSet.Tables("AccountsTable").Rows.Count = 0) Then
       MessageBox.Show("There are currently no registries in the database.")
    Else
       DataGridView1.DataSource = myDataSet.Tables("AccountsTable")
    End If
    End Sub
End Class


Customize your select query accordingly.
Hope this helps

For Connection String-
www.connectionstrings.com/[^]
~Edit~
~Added link~
 
Share this answer
 
v2
Comments
Member 8576082 18-Jan-12 2:11am    
Thank you, but my back end is mysql
manognya kota 18-Jan-12 2:15am    
check this link

http://www.go4expert.com/forums/showthread.php?t=2559

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