joe_pool_is Posted February 12, 2004 Posted February 12, 2004 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 Quote Avoid Sears Home Improvement
kahlua001 Posted February 12, 2004 Posted February 12, 2004 Whay are you using .ExecuteReader? if you are not selecting anything, use .ExecuteNonQuery Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.