Matrix generated Access mdb Update function not working

Discussion in 'ASP .Net Datagrid Control' started by Dave, Sep 1, 2003.

  1. Dave

    Dave Guest

    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.mdb"
    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
    Dave, Sep 1, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:Tsz4b.20060$...
    > 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.mdb"
    > 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
    >
    >
    Anthony Williams, Sep 10, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave
    Replies:
    1
    Views:
    536
    Anthony Williams
    Sep 10, 2003
  2. yma
    Replies:
    1
    Views:
    1,205
    Natty Gur
    Dec 16, 2003
  3. =?Utf-8?B?UGhpbA==?=

    Faster access to MDB? MS Access MDB and ASP

    =?Utf-8?B?UGhpbA==?=, Jan 26, 2005, in forum: ASP .Net
    Replies:
    8
    Views:
    473
    Kevin Spencer
    Jan 27, 2005
  4. Jonathan Upright

    MDB Database won't update

    Jonathan Upright, Oct 5, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    541
    Patirck Ige
    Oct 6, 2005
  5. John  Schult

    MDB to MDB Event Notification

    John Schult, May 4, 2005, in forum: Java
    Replies:
    0
    Views:
    471
    John Schult
    May 4, 2005
Loading...

Share This Page