Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Does anyone know how to update a MS Access file in VB.NET? My code currently looks this:

 

     Private Sub mnuSaveConfig_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSaveConfig.Click
       Dim strSQL As String, i As Short
       Dim objConnection As System.Data.OleDb.OleDbConnection
       Try
           objConnection = New System.Data.OleDb.OleDbConnection(strFile)
           objCommand = New System.Data.OleDb.OleDbCommand()
           objCommand.Connection = objConnection
           objCommand.Connection.Open()
       Catch val As Exception
           MessageBox.Show(val.Message, "Database Connection Error")
       End Try
       Try
           For i = 0 To Matrix.Length / 6 - 1  ' // 384 total Matrix entries, 6 Fields per Matrix row, therefore 384/6=64 rows, numbered 0 to 63.
               strSQL = "UPDATE Config " & _
                           "SET Name = " & Convert.ToString(Matrix(i, 1)) & ", " & _
                               "Address = " & Convert.ToString(Matrix(i, 2)) & ", " & _
                               "Level = " & Convert.ToString(Matrix(i, 3)) & ", " & _
                               "Switch Address = " & Convert.ToString(Matrix(i, 4)) & ", " & _
                               "I/O = " & Convert.ToString(Matrix(i, 5)) & " " & _
                           "WHERE ID = " & Convert.ToString(Matrix(i, 0))
               objCommand.CommandText = strSQL
               objCommand.ExecuteReader()
           Next
           objDataReader.Close()
           mnuSaveConfig.Enabled = False
       Catch val As Exception
           MessageBox.Show("Unable to safe settings." & vbCrLf & val.Message, "Configuration Error")
       End Try
   End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...