Friday, March 16, 2012

Passing a Variable

Hi All,

Please can you help...my code is not working when I try and pass my variable from page to another

Can anyone spot wots wrong here...i tHinks its to do with my error message...

many thanks

Tony

dim lota as integer

Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)

lota = Request.QueryString("lota")

If Not Page.IsPostBack Then
'if Not IsPostBack Then
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("/PWSC/" _
& "auction.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select LotNo, Date, title, txt " _
& "From Table1 " _
& "Where LotNo = &lota "_
& "Order By LotNo ", DBConn)
DBCommand.Fill(DSPageData, _
"LotDescription")
dg.DataSource = _
DSPageData.Tables("LotDescription").DefaultView
dg.DataBind()
dbconn.close
End If
End Sub

Exactly what is the problem? What is the error you are getting?

One possible problem is fixed here:


DBCommand = New OleDbDataAdapter _
("Select LotNo, Date, title, txt " _
& "From Table1 " _
& "Where LotNo = " & lota.ToString() _
& "Order By LotNo ", DBConn)

Declare variable as protected and see if you can access it.
Hello U have to pass this parameter &loto u don't give any value to that !

Try this

DbCommand.SelectCommand.CommandText = ("Select LotNo, Date, title, txt " _

& "From Table1 " _

& "Where LotNo = &lota "_

& "Order By LotNo ")

and Now add this Paramater
DbCommand.SelectCommand.Paramters.Add("&lota",lota )
and then fill and bind it should works I also recommend u to use ? instead & for mdb Database parameters !

I hope it helps !

0 comments:

Post a Comment