Web Matrix guide tour: INSERT in Access table fails

G

Guest

Hi

I followed the Web Matrix guided tour and came to the "ASP.NET Pages with
Data
(Microsoft Access)" part.

There is really not much you can do wrong there, but for some reason, the
INSERT part gives me an error. Here is the function that fails (appart from
the exception handling everything is generated by the code wizard):

Function InsertManufacturer(ByVal manufacturerCode As String, ByVal name As
String, ByVal address As String, ByVal webSite As String) As Integer
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\MatrixProjects.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "INSERT INTO [Manufacturer]
([ManufacturerCode], [Name], [Address], [WebSite]) VALUES (@ManufacturerCode,
@Name, @Address, @WebSite)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_manufacturerCode As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_manufacturerCode.ParameterName = "@ManufacturerCode"
dbParam_manufacturerCode.Value = manufacturerCode
dbParam_manufacturerCode.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_manufacturerCode)
Dim dbParam_name As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_name.ParameterName = "@Name"
dbParam_name.Value = name
dbParam_name.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_name)
Dim dbParam_address As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_address.ParameterName = "@Address"
dbParam_address.Value = address
dbParam_address.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_address)
Dim dbParam_webSite As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_webSite.ParameterName = "@WebSite"
dbParam_webSite.Value = webSite
dbParam_webSite.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_webSite)

Dim rowsAffected As Integer = 0
dim ex as exception ' To see what error it is
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Catch ex
msgLabel.Text = "Database Error: <br>" & ex.source & "<br>" & ex.message
& "<br>" & ex.stacktrace
msgLabel.Visible = true
Finally
dbConnection.Close
End Try

Return rowsAffected

End Function



The ex.message returns (danish):

"Handlingen skal bruge en opdaterbar forespørgsel"

which means something to the effect:

"Action needs an updatable query"

The ex.stacktrace says:

at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior,
Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at ASP.addManufacturer_aspx.InsertManufacturer(String manufacturerCode,
String name, String address, String webSite) in
C:\Inetpub\imcorp_asp\addManufacturer.aspx:line 58

Any idea? All other chapters worked like charm.
 
G

Guest

which language was that..Austrian,Norwegian,finnish or swedish!
The "Action needs an updatable query" error if i recall means you don't have
permission to write to the database file!
So go the the folder where the file exist or the file and make sure you have
the right access to write to the file!
GDLUCK
Patrick



Ekhaat said:
Hi

I followed the Web Matrix guided tour and came to the "ASP.NET Pages with
Data
(Microsoft Access)" part.

There is really not much you can do wrong there, but for some reason, the
INSERT part gives me an error. Here is the function that fails (appart from
the exception handling everything is generated by the code wizard):

Function InsertManufacturer(ByVal manufacturerCode As String, ByVal name As
String, ByVal address As String, ByVal webSite As String) As Integer
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\MatrixProjects.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "INSERT INTO [Manufacturer]
([ManufacturerCode], [Name], [Address], [WebSite]) VALUES (@ManufacturerCode,
@Name, @Address, @WebSite)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_manufacturerCode As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_manufacturerCode.ParameterName = "@ManufacturerCode"
dbParam_manufacturerCode.Value = manufacturerCode
dbParam_manufacturerCode.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_manufacturerCode)
Dim dbParam_name As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_name.ParameterName = "@Name"
dbParam_name.Value = name
dbParam_name.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_name)
Dim dbParam_address As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_address.ParameterName = "@Address"
dbParam_address.Value = address
dbParam_address.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_address)
Dim dbParam_webSite As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_webSite.ParameterName = "@WebSite"
dbParam_webSite.Value = webSite
dbParam_webSite.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_webSite)

Dim rowsAffected As Integer = 0
dim ex as exception ' To see what error it is
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Catch ex
msgLabel.Text = "Database Error: <br>" & ex.source & "<br>" & ex.message
& "<br>" & ex.stacktrace
msgLabel.Visible = true
Finally
dbConnection.Close
End Try

Return rowsAffected

End Function



The ex.message returns (danish):

"Handlingen skal bruge en opdaterbar forespørgsel"

which means something to the effect:

"Action needs an updatable query"

The ex.stacktrace says:

at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior,
Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at ASP.addManufacturer_aspx.InsertManufacturer(String manufacturerCode,
String name, String address, String webSite) in
C:\Inetpub\imcorp_asp\addManufacturer.aspx:line 58

Any idea? All other chapters worked like charm.
 
G

Guest

Ohhh...., You are the best, well, better than me anyway :)

Thank you



Patrick.O.Ige said:
which language was that..Austrian,Norwegian,finnish or swedish!
The "Action needs an updatable query" error if i recall means you don't have
permission to write to the database file!
So go the the folder where the file exist or the file and make sure you have
the right access to write to the file!
GDLUCK
Patrick



Ekhaat said:
Hi

I followed the Web Matrix guided tour and came to the "ASP.NET Pages with
Data
(Microsoft Access)" part.

There is really not much you can do wrong there, but for some reason, the
INSERT part gives me an error. Here is the function that fails (appart from
the exception handling everything is generated by the code wizard):

Function InsertManufacturer(ByVal manufacturerCode As String, ByVal name As
String, ByVal address As String, ByVal webSite As String) As Integer
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\MatrixProjects.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "INSERT INTO [Manufacturer]
([ManufacturerCode], [Name], [Address], [WebSite]) VALUES (@ManufacturerCode,
@Name, @Address, @WebSite)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_manufacturerCode As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_manufacturerCode.ParameterName = "@ManufacturerCode"
dbParam_manufacturerCode.Value = manufacturerCode
dbParam_manufacturerCode.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_manufacturerCode)
Dim dbParam_name As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_name.ParameterName = "@Name"
dbParam_name.Value = name
dbParam_name.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_name)
Dim dbParam_address As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_address.ParameterName = "@Address"
dbParam_address.Value = address
dbParam_address.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_address)
Dim dbParam_webSite As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_webSite.ParameterName = "@WebSite"
dbParam_webSite.Value = webSite
dbParam_webSite.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_webSite)

Dim rowsAffected As Integer = 0
dim ex as exception ' To see what error it is
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Catch ex
msgLabel.Text = "Database Error: <br>" & ex.source & "<br>" & ex.message
& "<br>" & ex.stacktrace
msgLabel.Visible = true
Finally
dbConnection.Close
End Try

Return rowsAffected

End Function



The ex.message returns (danish):

"Handlingen skal bruge en opdaterbar forespørgsel"

which means something to the effect:

"Action needs an updatable query"

The ex.stacktrace says:

at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior,
Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at ASP.addManufacturer_aspx.InsertManufacturer(String manufacturerCode,
String name, String address, String webSite) in
C:\Inetpub\imcorp_asp\addManufacturer.aspx:line 58

Any idea? All other chapters worked like charm.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top