1 Replies - 8077 Views - Last Post: 16 September 2010 - 09:52 AM Rate Topic: -----

#1 Guest_choong1990*


Reputation:

compare the data from textbox with sql data

Posted 15 September 2010 - 08:22 PM

my asp have a textbox and a button, while user enter "trackingNum" and click the button, it will compare the textbox.text with the sql table "package"data. Finally it will display the result of another column "CurrentLocation" else display "not found".

now the problem is i tried to link it together but i have no idea how to compare the data.
 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim connection As New SqlConnection()
        Dim query As String = "Select * from package where trackingNum=@trackingNum and CurrectLocation=@CurrentLocation"
        Dim command As New SqlCommand(query, connection)


        connection.ConnectionString = ConnString
        connection.Open()

        Dim reader As SqlDataReader = command.ExecuteReader()


these code is what i found in internet, and i need help of how to compare the data from sql. thx

Is This A Good Question/Topic? 0

Replies To: compare the data from textbox with sql data

#2 keakTheGEEK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 107
  • View blog
  • Posts: 344
  • Joined: 23-February 10

Re: compare the data from textbox with sql data

Posted 16 September 2010 - 09:52 AM

If you're returning data from CurrentLocation column based on if the input is equal to data in your TrackingNumber column then you can do that in SQL like this:

SELECT currentlocation FROM package
WHERE trackingnum = @TrackingNum



Then after you execute the command, you can return the data in VB .NET like so:
        If reader.HasRows Then
            Do While reader.Read()
                'Get the currentlocation reader.GetString(0) and do something with it
                
            Loop
        Else
           'No rows found
        End If

        reader.Close()



However, before you execute your command you will need to create a parameter for @TrackingNum. You should read this link on msdn on the details for configuring parameters for SqlConnections. You will set the value of the parameter to textbox.Text property. Hope this helps...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1