.NET Forum / ASP.NET / General / August 2007
problem with .aspx code
|
|
Thread rating:  |
slinky - 03 Aug 2007 20:45 GMT 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
Alexey Smirnov - 03 Aug 2007 21:07 GMT > I have a form that has 6 Textboxes to enter data and a button to > write [quoted text clipped - 21 lines] > 3) Private Sub Page_Load(ByVal sender As System.Object, _ > 4) ByVal e As System.EventArgs) Handles MyBase.Load you should define the class in *.aspx.vb file
Imports System.Data Imports System.Data.OleDb
Public Class MyFirstPageName Inherits System.Web.UI.Page
......
End Class
A class name (MyFirstPageName) should be the same as in your *.aspx file
<%@ Page Inherits="MyFirstPageName" ...
slinky - 03 Aug 2007 21:58 GMT OK I did that, now 23 erros popped up. The name of the file below is Lowes3.aspx.vb Lines 3, 5, 6, 7, 25-33, 40-46 (e.g.
Imports System.Data Imports System.Data.OleDb Public Class Lowes3.aspx Inherits System.Web.UI.Page <End of statement expected Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load <event 'Load' cannot be found If IsPostBack Then Dim cnn As OleDbConnection("data Source=(local);" & _ <array bounds cannot appear in type specifiers "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)" <sysntaz error cmdInsert.Parameters.Add(@Asset_Number" , OleDbType. 10," Asset_Number") < '@' not valid cmdInsert.Parameters.Add(@Description" , OleDbType.VarChar, 40," Description") < '@' not valid cmdInsert.Parameters.Add(@Serial_Number" , OleDbType.VarChar, 30," Serial_Number") < '@' not valid cmdInsert.Parameters.Add(@Mfg" , _OleDbType.VarChar, _30," Mfg") < '@' not valid cmdInsert.Parameters.Add(@RDCnumber" , OleDbType.VarChar, 30," RDCnumber") < '@' not valid cmdInsert.Parameters.Add(@AssetType" , OleDbType.VarChar, 30," AssetType") < '@' not valid cmdInsert.Parameters(@Asset_Number"). _ < Property access must assign to the property or use its value SourceVersion = _ < Name 'Source Version' is not declared 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 < txtAsset_Number - not declared dr(1) = txtDescription.Text ditto dr(2) = txtSerial_Number.Text ditto dr(3) = txtMfg.Text ditto dr(4) = txtRDCnumber.Text ditto dr(5) = txtAssetType.Text ditto Ds.Tables("Assets".Rows.Add.(dr) < Property access must assign to the property or use its value da.Update(ds, "Assets") End If End Sub End Class
> you should define the class in *.aspx.vb file > [quoted text clipped - 13 lines] > > - Show quoted text - Alexey Smirnov - 03 Aug 2007 23:21 GMT > OK I did that, now 23 erros popped up. The name of the file below is > Lowes3.aspx.vb [quoted text clipped - 4 lines] > Public Class Lowes3.aspx Inherits System.Web.UI.Page <End of > statement expected 1) "Inherits System.Web.UI.Page" should start from a new line, like here
Partial Public Class <classname> Inherits System.Web.UI.Page
2) Class name should be "Lowes3" (without the ".aspx")
I think the easiest way to learn, is to create a new empty page to see what IDE added to ASPX and VB files by default. Then you can copy the code from your book to existing template...
slinky - 06 Aug 2007 05:16 GMT I did take care of this order of code:
Imports System.Data Imports System.Data.OleDb Public Class Lowes3 Inherits System.Web.UI.Page
This got rid of some errors but the follwing remain. I started from scratch using IDE and in most cases nothing droppeddown that was usable. Would the code be a problem since I used SQLserver code modified for an OleDB??
Here's the error lines that remain:
Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load <event 'Load' cannot be found If IsPostBack Then Dim cnn As OleDbConnection("data Source=(local);" & _ <array bounds cannot appear in type specifiers
"VALUES(@Asset_Number, @Description, @Serial_Number, @Mfg, @RDCnumber, @AssetType)" <syntax error cmdInsert.Parameters.Add(@Asset_Number" , OleDbType. 10," Asset_Number") < '@' not valid cmdInsert.Parameters.Add(@Description" , OleDbType.VarChar, 40," Description") < '@' not valid cmdInsert.Parameters.Add(@Serial_Number" , OleDbType.VarChar, 30," Serial_Number") < '@' not valid cmdInsert.Parameters.Add(@Mfg" , _OleDbType.VarChar, _30," Mfg") < '@' not valid cmdInsert.Parameters.Add(@RDCnumber" , OleDbType.VarChar, 30," RDCnumber") < '@' not valid cmdInsert.Parameters.Add(@AssetType" , OleDbType.VarChar, 30," AssetType") < '@' not valid cmdInsert.Parameters(@Asset_Number"). _ < Property access must assign to the property or use its value SourceVersion = _ < Name 'Source Version' is not declared
txtAsset_Number.Text < txtAsset_Number - not declared dr(1) = txtDescription.Text ditto dr(2) = txtSerial_Number.Text ditto dr(3) = txtMfg.Text ditto dr(4) = txtRDCnumber.Text ditto dr(5) = txtAssetType.Text ditto
Ds.Tables("Assets".Rows.Add.(dr) < Property access must assign to the property or use its value
> > OK I did that, now 23 erros popped up. The name of the file below is > > Lowes3.aspx.vb [quoted text clipped - 16 lines] > what IDE added to ASPX and VB files by default. Then you can copy the > code from your book to existing template...
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|