By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,494 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,494 IT Pros & Developers. It's quick & easy.

Matrix generated Access mdb Update function not working

P: n/a
Ok then... simple little exercise for me to learn ASP.NET and the simplest
things are hanging me up. Like this:

I have an .mdb that I am using the Matrix generated Select code to read
from. The SELECT function it generates works fine.

Now I am trying to Update one of the records in the little .mdb... the first
record... the following code executes without error, but nothing changes in
the .mdb either. What simple little thing am I missing?

I call it with this code, the function is below.

dim thisKey as integer = 1
dim thisSpecies as string = "a"
dim thisStage as string ="a"

UpdateAvail(thisKey, thisSpecies,thisStage)

All code below is generated by the Matrix Update tool.

Function UpdateAvail(ByVal key As Integer, ByVal species As String,
ByVal stage As String) As Integer
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=C:\Inetpub\wwwroot\mynextbird\mynextbird.md b"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )

Dim queryString As String = "UPDATE [Avail] SET
[Species]=@Species, [Stage]=@Stage WHERE ([Avail].[Key] = @Key)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_key As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_key.ParameterName = "@Key"
dbParam_key.Value = key
dbParam_key.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_key)
Dim dbParam_species As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_species.ParameterName = "@Species"
dbParam_species.Value = species
dbParam_species.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_species)
Dim dbParam_stage As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_stage.ParameterName = "@Stage"
dbParam_stage.Value = stage
dbParam_stage.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_stage)

Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try

Return rowsAffected
End Function
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
If nothing is happening to the MDB then it's likely an error's being thrown
in the Try...End Try statement.

However, because you're not catching any exceptions, what you're doing is
just ignoring any errors that are thrown. Try commenting out the Try...End
Try statements and see what happens - it's probable that you'll encounter an
error, and when you do, it'll give you a little more information on where to
start looking.

Do that and if you can't fix it, post a reply here.

Cheers,
Anth

"Dave" <d@d.com> wrote in message
news:Ts******************@twister.austin.rr.com...
Ok then... simple little exercise for me to learn ASP.NET and the simplest
things are hanging me up. Like this:

I have an .mdb that I am using the Matrix generated Select code to read
from. The SELECT function it generates works fine.

Now I am trying to Update one of the records in the little .mdb... the first record... the following code executes without error, but nothing changes in the .mdb either. What simple little thing am I missing?

I call it with this code, the function is below.

dim thisKey as integer = 1
dim thisSpecies as string = "a"
dim thisStage as string ="a"

UpdateAvail(thisKey, thisSpecies,thisStage)

All code below is generated by the Matrix Update tool.

Function UpdateAvail(ByVal key As Integer, ByVal species As String, ByVal stage As String) As Integer
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=C:\Inetpub\wwwroot\mynextbird\mynextbird.md b"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )

Dim queryString As String = "UPDATE [Avail] SET
[Species]=@Species, [Stage]=@Stage WHERE ([Avail].[Key] = @Key)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_key As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_key.ParameterName = "@Key"
dbParam_key.Value = key
dbParam_key.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_key)
Dim dbParam_species As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_species.ParameterName = "@Species"
dbParam_species.Value = species
dbParam_species.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_species)
Dim dbParam_stage As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_stage.ParameterName = "@Stage"
dbParam_stage.Value = stage
dbParam_stage.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_stage)

Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try

Return rowsAffected
End Function

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.