S
slinky
I have a form that has 6 Textboxes to enter data and a button to
write
the data to my Access database which resides on the same server as my
website. It's an .aspx page. I find no errors except the 3rd and 4th
lines throw errors. I got this basic example from a book (Written by
Mike Gunderloy for
MS Exam 70-305 page 481) which said to, while in design view, double
click the button to open the form's
module and place the code below. Just a thought, but the book didn't
mention this
but how does the code know that clicking the Submit button should run
the Page_Load?
I'm using Visual Web Developer 2005
Express. Any clues? Thanks!!!
Line numbers for reference only - here's my errors:
Line 3: Private Sub Page_Load(ByVal sender As System.Object, _
Statement is not valid in a namespace.
Line 4: ByVal e As System.EventArgs) Handles MyBase.Load
Statement is not valid in a namespace.
Imports System.Data
Imports System.Data.OleDb
3) Private Sub Page_Load(ByVal sender As System.Object, _
4) ByVal e As System.EventArgs) Handles MyBase.Load
If IsPostBack Then
Dim cnn As OleDbConnection("data Source=(local);" & _
"Initial Catalog=Lowes;" & _
"Integrated Security=SSPI")
Dim cnn As OleDbConnection
Dim ds As DataSet = New DataSet()
Dim da As OleDbDataAdapter = _
New OleDbDataAdapter()
Dim cmdSelect As OleDbCommand = _
Cnn.CreateCommand()
cmdSelect.CommandType = CommandType.Text
cmdSelect.CommandText = _
"SELECT Asset_Number, Description, Serial_Number, Mfg, RDCnumber,
AssetType FROM Assets"
Dim cmdInsert As OleDbCommand = _
Cnn.CreateCommand()
cmdInsert.CommandType = CommandType.Text
cmdInsert.CommandText = _
"INSERT INTO Customers " & _
"(Asset_Number, Description, Serial_Number, Mfg, RDCnumber,
AssetType) "
"VALUES(@Asset_Number, @Description, @Serial_Number, @Mfg,
@RDCnumber,
@AssetType)"
cmdInsert.Parameters.Add(@Asset_Number" , OleDbType. 10,"
Asset_Number")
cmdInsert.Parameters.Add(@Description" , OleDbType.VarChar, 40,"
Description")
cmdInsert.Parameters.Add(@Serial_Number" , OleDbType.VarChar, 30,"
Serial_Number")
cmdInsert.Parameters.Add(@Mfg" , _OleDbType.VarChar, _30," Mfg")
cmdInsert.Parameters.Add(@RDCnumber" , OleDbType.VarChar, 30,"
RDCnumber")
cmdInsert.Parameters.Add(@AssetType" , OleDbType.VarChar, 30,"
AssetType")
cmdInsert.Parameters(@Asset_Number"). _
SourceVersion = _
DataRowVersion.Original
da.SelectCommand = cmdSelect
da.InsertCommand = cmdInsert
da.Fill(ds, "Assets")
Dim dr As DataRow = ds.Tables( _
"Assets").NewRow()
dr(0) = txtAsset_Number.Text
dr(1) = txtDescription.Text
dr(2) = txtSerial_Number.Text
dr(3) = txtMfg.Text
dr(4) = txtRDCnumber.Text
dr(5) = txtAssetType.Text
Ds.Tables("Assets".Rows.Add.(dr)
da.Update(ds, "Assets")
End If
End Sub
write
the data to my Access database which resides on the same server as my
website. It's an .aspx page. I find no errors except the 3rd and 4th
lines throw errors. I got this basic example from a book (Written by
Mike Gunderloy for
MS Exam 70-305 page 481) which said to, while in design view, double
click the button to open the form's
module and place the code below. Just a thought, but the book didn't
mention this
but how does the code know that clicking the Submit button should run
the Page_Load?
I'm using Visual Web Developer 2005
Express. Any clues? Thanks!!!
Line numbers for reference only - here's my errors:
Line 3: Private Sub Page_Load(ByVal sender As System.Object, _
Statement is not valid in a namespace.
Line 4: ByVal e As System.EventArgs) Handles MyBase.Load
Statement is not valid in a namespace.
Imports System.Data
Imports System.Data.OleDb
3) Private Sub Page_Load(ByVal sender As System.Object, _
4) ByVal e As System.EventArgs) Handles MyBase.Load
If IsPostBack Then
Dim cnn As OleDbConnection("data Source=(local);" & _
"Initial Catalog=Lowes;" & _
"Integrated Security=SSPI")
Dim cnn As OleDbConnection
Dim ds As DataSet = New DataSet()
Dim da As OleDbDataAdapter = _
New OleDbDataAdapter()
Dim cmdSelect As OleDbCommand = _
Cnn.CreateCommand()
cmdSelect.CommandType = CommandType.Text
cmdSelect.CommandText = _
"SELECT Asset_Number, Description, Serial_Number, Mfg, RDCnumber,
AssetType FROM Assets"
Dim cmdInsert As OleDbCommand = _
Cnn.CreateCommand()
cmdInsert.CommandType = CommandType.Text
cmdInsert.CommandText = _
"INSERT INTO Customers " & _
"(Asset_Number, Description, Serial_Number, Mfg, RDCnumber,
AssetType) "
"VALUES(@Asset_Number, @Description, @Serial_Number, @Mfg,
@RDCnumber,
@AssetType)"
cmdInsert.Parameters.Add(@Asset_Number" , OleDbType. 10,"
Asset_Number")
cmdInsert.Parameters.Add(@Description" , OleDbType.VarChar, 40,"
Description")
cmdInsert.Parameters.Add(@Serial_Number" , OleDbType.VarChar, 30,"
Serial_Number")
cmdInsert.Parameters.Add(@Mfg" , _OleDbType.VarChar, _30," Mfg")
cmdInsert.Parameters.Add(@RDCnumber" , OleDbType.VarChar, 30,"
RDCnumber")
cmdInsert.Parameters.Add(@AssetType" , OleDbType.VarChar, 30,"
AssetType")
cmdInsert.Parameters(@Asset_Number"). _
SourceVersion = _
DataRowVersion.Original
da.SelectCommand = cmdSelect
da.InsertCommand = cmdInsert
da.Fill(ds, "Assets")
Dim dr As DataRow = ds.Tables( _
"Assets").NewRow()
dr(0) = txtAsset_Number.Text
dr(1) = txtDescription.Text
dr(2) = txtSerial_Number.Text
dr(3) = txtMfg.Text
dr(4) = txtRDCnumber.Text
dr(5) = txtAssetType.Text
Ds.Tables("Assets".Rows.Add.(dr)
da.Update(ds, "Assets")
End If
End Sub