Hi,
I am trying to return data from a database using an SQL query. I want the data to be displayed in a datagrid. The SQL query Is formatted in the usual way with SELECT .... FROM ... WHERE
The where is getting an input from a textbox on the screen. I want the datagrid to be populated with the only the data that matches the search criteria upon the click of a button. No matter what I have tried it has not worked and my head is starting to get sore from scatching it!
The code looks like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not Page.IsPostBack Then
DataGridMaster.SelectedIndex = 0
'BindMaster()
Surname = txtSurname.Text
Dim strQuery As String = "Select Surname, Other_Names, Matter, Client_Number, Department, [Fee Earner], Work_Type, HTR_Reference, Initiating_Fee_Earner, Archive_Date, Destroy_Date, Box_Number, Comments, House_Number, Address_1, Address_2, Town, Postcode FROM tblEYWStest WHERE Surname = '" & Surname & "'"
Dim objConn As New SqlConnection(strConnection)
Dim dataAdapter As New SqlDataAdapter(strQuery, objConn)
Dim ds As New DataSet()
dataAdapter.Fill(ds)
DataGridMaster.DataSource = ds
DataGridMaster.DataBind()
End If
End Sub
I have only been able to get the datagrid to populate upon the page_load method so far and it only loads the whole database, which is a problem as the database has about 16,000 entries!
I am sure that searching a database for a specific entry is quite easy and that it is something realy stupid that I am doing wrong.
Any help would be greatly appreciated.
Cheers
Ashley :)