W
William
After much frustration I was able to update my data store via code only.
Using the data adapter was the only way I was able to set up all the objects
written in my code. Basically, I cheated by creating an adapter and then
copy, paste, modify it's code to suite my needs. This was the end result:
Private sub updateTable( )
Dim myData As DataSet
'Command is a form level oledbcommand object
Dim Adapter1 As New OleDbDataAdapter(Command)
myData = New DataSet()
myData = Me.DataGrid1.DataSource
Dim Cno As OleDbConnection
Cno = New OleDbConnection(Me.strConnectionString)
'**************************************************
' here is where my copy, paste, modify code from
'adapter control starts
'*************************************************
Adapter1.UpdateCommand = New OleDbCommand()
'best way to get parameters and update string is to create them
'using an oledbdataadapter control
Dim strUpdate As String = "UPDATE employee SET [Employee Number] = ?, [First
Name] = ?, [Last Name] = ? WHER" & _
"E ([Employee Number] = ?) AND ([First Name] = ? OR ? IS NULL AND [First
Name] IS" & _
" NULL) AND ([Last Name] = ? OR ? IS NULL AND [Last Name] IS NULL)"
With Adapter1.UpdateCommand
..CommandText = strUpdate
..Connection = Cno
..Parameters.Add(New OleDbParameter("Employee_Number",
System.Data.OleDb.OleDbType.SmallInt, 0,
System.Data.ParameterDirection.Input, False, CType(5, Byte), CType(0, Byte),
"Employee Number", System.Data.DataRowVersion.Current, Nothing))
..Parameters.Add(New OleDbParameter("First_Name",
System.Data.OleDb.OleDbType.VarWChar, 25, "First Name"))
..Parameters.Add(New OleDbParameter("Last_Name",
System.Data.OleDb.OleDbType.VarWChar, 25, "Last Name"))
..Parameters.Add(New OleDbParameter("Original_Employee_Number",
System.Data.OleDb.OleDbType.SmallInt, 0,
System.Data.ParameterDirection.Input, False, CType(5, Byte), CType(0, Byte),
"Employee Number", System.Data.DataRowVersion.Original, Nothing))
..Parameters.Add(New OleDbParameter("Original_First_Name",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"First Name", System.Data.DataRowVersion.Original, Nothing))
..Parameters.Add(New OleDbParameter("Original_First_Name1",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"First Name", System.Data.DataRowVersion.Original, Nothing))
..Parameters.Add(New OleDbParameter("Original_Last_Name",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Last Name", System.Data.DataRowVersion.Original, Nothing))
..Parameters.Add(New OleDbParameter("Original_Last_Name1",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Last Name", System.Data.DataRowVersion.Original, Nothing))
End With
'***************************************
'here is where it ends
'***************************************
Try
Adapter1.Update(myData.Tables(0))
Catch prob As OleDbException
MsgBox(prob.Message)
End Try
end sub
I was never able to get the commandbuilder to work. I just think this is a
lot of coding where is previous version doing this in code was much simpler.
Have I just been spoiled by vb6 and it's simplicity?
Using the data adapter was the only way I was able to set up all the objects
written in my code. Basically, I cheated by creating an adapter and then
copy, paste, modify it's code to suite my needs. This was the end result:
Private sub updateTable( )
Dim myData As DataSet
'Command is a form level oledbcommand object
Dim Adapter1 As New OleDbDataAdapter(Command)
myData = New DataSet()
myData = Me.DataGrid1.DataSource
Dim Cno As OleDbConnection
Cno = New OleDbConnection(Me.strConnectionString)
'**************************************************
' here is where my copy, paste, modify code from
'adapter control starts
'*************************************************
Adapter1.UpdateCommand = New OleDbCommand()
'best way to get parameters and update string is to create them
'using an oledbdataadapter control
Dim strUpdate As String = "UPDATE employee SET [Employee Number] = ?, [First
Name] = ?, [Last Name] = ? WHER" & _
"E ([Employee Number] = ?) AND ([First Name] = ? OR ? IS NULL AND [First
Name] IS" & _
" NULL) AND ([Last Name] = ? OR ? IS NULL AND [Last Name] IS NULL)"
With Adapter1.UpdateCommand
..CommandText = strUpdate
..Connection = Cno
..Parameters.Add(New OleDbParameter("Employee_Number",
System.Data.OleDb.OleDbType.SmallInt, 0,
System.Data.ParameterDirection.Input, False, CType(5, Byte), CType(0, Byte),
"Employee Number", System.Data.DataRowVersion.Current, Nothing))
..Parameters.Add(New OleDbParameter("First_Name",
System.Data.OleDb.OleDbType.VarWChar, 25, "First Name"))
..Parameters.Add(New OleDbParameter("Last_Name",
System.Data.OleDb.OleDbType.VarWChar, 25, "Last Name"))
..Parameters.Add(New OleDbParameter("Original_Employee_Number",
System.Data.OleDb.OleDbType.SmallInt, 0,
System.Data.ParameterDirection.Input, False, CType(5, Byte), CType(0, Byte),
"Employee Number", System.Data.DataRowVersion.Original, Nothing))
..Parameters.Add(New OleDbParameter("Original_First_Name",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"First Name", System.Data.DataRowVersion.Original, Nothing))
..Parameters.Add(New OleDbParameter("Original_First_Name1",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"First Name", System.Data.DataRowVersion.Original, Nothing))
..Parameters.Add(New OleDbParameter("Original_Last_Name",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Last Name", System.Data.DataRowVersion.Original, Nothing))
..Parameters.Add(New OleDbParameter("Original_Last_Name1",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Last Name", System.Data.DataRowVersion.Original, Nothing))
End With
'***************************************
'here is where it ends
'***************************************
Try
Adapter1.Update(myData.Tables(0))
Catch prob As OleDbException
MsgBox(prob.Message)
End Try
end sub
I was never able to get the commandbuilder to work. I just think this is a
lot of coding where is previous version doing this in code was much simpler.
Have I just been spoiled by vb6 and it's simplicity?