problem with retrieving/displaying data based on form input

Last post 02-23-2007 8:20 AM by tomosap. 4 replies.

Sort Posts:

  • problem with retrieving/displaying data based on form input

    02-22-2007, 5:45 PM
    • Loading...
    • tomosap
    • Joined on 02-19-2007, 5:18 PM
    • Wales, United Kingdom
    • Posts 15

    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

  • Re: problem with retrieving/displaying data based on form input

    02-22-2007, 9:21 PM

    Dear, friend:

    I am sorry that i have not caught your meaning completely.

    Do you mean in this statement

    GridView.DataSource = recordAdapter.GetDataByExt(ExtTxt.Text)

    ExtTxt.Text returns the right value which you input into the TextBox but the result of  recordAdapter.GetDataByExt(ExtTxt.Text) is not as you expect?

    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
  • Re: problem with retrieving/displaying data based on form input

    02-23-2007, 3:35 AM
    • Loading...
    • tomosap
    • Joined on 02-19-2007, 5:18 PM
    • Wales, United Kingdom
    • Posts 15

    Hi,

     No, it's the

    GridView.DataSource = recordAdapter.GetDataByEmail(EmailTxt.Text)

    which is causing the problem - If I uncomment this IF statement, then the form works, but for some reason it no longer works if I try to search by Name or Surname - I don't understand why this is as when I check the value of NameTxt.Text or SurnameTxt.Txt during debug mode, it shows that the string is what I entered.

    Thanks,

    Tom

  • Re: problem with retrieving/displaying data based on form input

    02-23-2007, 4:53 AM
    Answer
    • Loading...
    • kakali
    • Joined on 02-01-2007, 10:37 AM
    • Posts 133

    Hi!,
    Just in case...

    In ur if statement u have used Email.text (name of the textbox control is Email), whereas next line u r assigning null value to Emailtxt (name of the control is EmailTxt), is it typo.

     

     

    Regards
  • Re: problem with retrieving/displaying data based on form input

    02-23-2007, 8:20 AM
    • Loading...
    • tomosap
    • Joined on 02-19-2007, 5:18 PM
    • Wales, United Kingdom
    • Posts 15

    Hi,

    Thanks for noticing that - Guess all it takes sometimes is a fresh set of eyes Big Smile

    Edited it to be correct, and all is working now - Cheers!!

    In addition, can anyone suggest a method of creating a way of joining the searches so that if someone enters a Name and Surname which don't exist or don't match the database values, it displays a message to say that it has no entries ?

    Thanks, Tom.

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter