I'm relatively new to working with VB .NET, especially working with data sets and updating databases.
I'm having a heck of a time trying to take a value entered by the user in a form and write this to an Access table. I've tried at least 15 different things pulling information from MSDN, web, etc. and can't seem to find an answer, the code I've written has made sense and will often execute but not write anything at all to the table.
The table I'm writing to has an autonumber.
Could any of you point me in the direction of where I can find a walk through?
Also, I'm planning on upgrading Access tables to SQL Server, will this have a huge impact?
Here is the most recent code I've tried that doesn't work:
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
'Save data to transaction value table
Dim i, intCode, intField_id As Integer
Dim strDataSave(), strSQL As String
Dim dtCurrentDate As Date
Dim da As System.Data.OleDb.OleDbDataAdapter
Dim cmd As System.Data.OleDb.OleDbCommand
dtCurrentDate = Now 'Timestamp
For i = 0 To 14
If CurrentInfo(i) <> "" Then
'Identify the field Code
strDataSave = Split(CurrentInfo(i), "|")
'Define SQL string to populate current data table
cmd = New System.Data.OleDb.OleDbCommand("INSERT INTO tbl_CurrentData(Currentdata_date, currentdata_value, field_id, loan_num" & _
"VALUES ('" & dtCurrentDate & "','" & strDataSave(0) & "','" & strDataSave(1) & "','" & strLoanNum & "')", ODBC)
cmd.Parameters.Add("'" & dtCurrentDate & "'", System.Data.OleDb.OleDbType.DBDate, 0, "currentdata_date")
cmd.Parameters.Add("'" & strDataSave(0) & "'", System.Data.OleDb.OleDbType.VarWChar, 50, "currentdata_value")
cmd.Parameters.Add("'" & strDataSave(1) & "'", System.Data.OleDb.OleDbType.SmallInt, 0, "field_id")
cmd.Parameters.Add("'" & strLoanNum & "'", System.Data.OleDb.OleDbType.VarWChar, 10, "loan_num")
da.InsertCommand = cmd
End If
Next
End Sub
I'm having a heck of a time trying to take a value entered by the user in a form and write this to an Access table. I've tried at least 15 different things pulling information from MSDN, web, etc. and can't seem to find an answer, the code I've written has made sense and will often execute but not write anything at all to the table.
The table I'm writing to has an autonumber.
Could any of you point me in the direction of where I can find a walk through?
Also, I'm planning on upgrading Access tables to SQL Server, will this have a huge impact?
Here is the most recent code I've tried that doesn't work:
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
'Save data to transaction value table
Dim i, intCode, intField_id As Integer
Dim strDataSave(), strSQL As String
Dim dtCurrentDate As Date
Dim da As System.Data.OleDb.OleDbDataAdapter
Dim cmd As System.Data.OleDb.OleDbCommand
dtCurrentDate = Now 'Timestamp
For i = 0 To 14
If CurrentInfo(i) <> "" Then
'Identify the field Code
strDataSave = Split(CurrentInfo(i), "|")
'Define SQL string to populate current data table
cmd = New System.Data.OleDb.OleDbCommand("INSERT INTO tbl_CurrentData(Currentdata_date, currentdata_value, field_id, loan_num" & _
"VALUES ('" & dtCurrentDate & "','" & strDataSave(0) & "','" & strDataSave(1) & "','" & strLoanNum & "')", ODBC)
cmd.Parameters.Add("'" & dtCurrentDate & "'", System.Data.OleDb.OleDbType.DBDate, 0, "currentdata_date")
cmd.Parameters.Add("'" & strDataSave(0) & "'", System.Data.OleDb.OleDbType.VarWChar, 50, "currentdata_value")
cmd.Parameters.Add("'" & strDataSave(1) & "'", System.Data.OleDb.OleDbType.SmallInt, 0, "field_id")
cmd.Parameters.Add("'" & strLoanNum & "'", System.Data.OleDb.OleDbType.VarWChar, 10, "loan_num")
da.InsertCommand = cmd
End If
Next
End Sub