silversasoriza:hi, i wanted to check whether the transactionID is correct or not from the database(access). if it is correct, then i would like to display the data in the correct row to a text file. so far, i can validate succesfully. However, im having trouble to get the whole row and display it.
Kamii47 is suggesting that you batch commands; this may or may not be
possible depending on your database. With SQL Server it is possible,
with Access it is not. Since you are using an OleDbCommand I suspect
you are not using SQL Server.
Will the COUNT(*) ever return anything other than a 0 or 1? That is, would there only be 1 record per trackingNo, or multiple records?
Since you are trying to place the result in a single textbox, I am going to assume there would only be 1 record per tracking No. In that case, I would suggest code like this (note that I used a parameter; never concatenate UI-supplied data to a SQL string to be execute, this is insecure and opens up your application to SQL injection attacks):
Imports System.Data.OleDb
Imports homepage.configuration1
Public Class orderTracking
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim config1 As New homepage.configuration1
Dim strcon As String = config1.get_connection()
Dim con As OleDbConnection
Dim cmd As New OleDbCommand
Dim shippingCost As String
'create a new connection
con = New OleDbConnection(strcon)
'create sql statement
cmd.CommandText = "SELECT shippingCost from shipment where trackingNo = ?"
cmd.Parameters.Add("trackingNo", OleDbType.VarChar, 50).Value = txtBoxOrderNo.Text
cmd.Connection = con
con.Open()
shippingCost = cmd.ExecuteScalar()
If IsDbNull(shippingCost) Then
lbError.Text = "No match found"
Else
txtBoxShipMethod.Text = shippingCost
'lbCorrect.Text = "Found"
End If
End Sub
End Class
Terri Morton
Program Manager, Telligent
Wissen ist MachtHow to ask a question