Hi,
I've developed a form which accesses a database through a data layer and sends parameters based on the form input. I have written the following code which works by checking if the textbox is empty and passing a null value as a string to the search parameter in the query, of which there are five: Name, Surname, Email, Ext, Dept. This is the code that I have written to check achieve this:
Protected Sub SearchBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchBtn.Click
Dim recordAdapter As New recordTableAdapter
If
(NameTxt.Text = String.Empty) Then
NameTxt.Text = DBNull.Value.ToString
Else
GridView.DataSource = recordAdapter.GetDataByName(NameTxt.Text)
End If
'
If (SurnameTxt.Text = String.Empty) Then
SurnameTxt.Text = DBNull.Value.ToString
Else
GridView.DataSource = recordAdapter.GetDataBySurname(SurnameTxt.Text)
End If
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'If (Email.Text = String.Empty) Then
'EmailTxt.Text = DBNull.Value.ToString
'Else
'GridView.DataSource = recordAdapter.GetDataByEmail(EmailTxt.Text)
'End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Above seems to be causing a clash with the rest and causing search to not function properly
'
If (ExtTxt.Text = String.Empty) Then
ExtTxt.Text = DBNull.Value.ToString
Else
GridView.DataSource = recordAdapter.GetDataByExt(ExtTxt.Text)
End If
'
If (DeptTxt.Text = String.Empty) Then
DeptTxt.Text = DBNull.Value.ToString
Else
GridView.DataSource = recordAdapter.GetDataByDept(DeptTxt.Text)
End If
GridView.DataBind()
End Sub
I have commented out the email search as if I enable this, for some reason it stops accepting input paramters from Name and Surname. When I use the debugger and set a line break at either the Name or Surname 'Get' command, I can see that the value for the string is what I entered in the textbox, yet it doesn't want to use them in the search and it comes up blank as if it couldn't find anything. Any Ideas ?!?!
Also, I want to introduce a function where if a user enters a search where it cannot find any records based on the search criteria, I want a message to come up saying that it cannot find anything. If anyone can help me with this, I'd be grateful.
Many thanks in advance,
Tom