cjaymcmeans
Well-known member
- Joined
- Jan 12, 2005
- Messages
- 85
- Programming Experience
- 3-5
im using a standard class function to assign values to a command...
the function seem to be working just fine...
the problem is whenever i try to update a certain record it only goes as far as the dataset... the database doesnt get updated... the insert command works though.. i dont know what the problem is primarily because they both run through the same functions in my class...
hope you guys can help... tnx...
Public Sub Equate(ByVal Xrow As DataRow, ByVal UId As String, ByVal fname As String, ByVal lname As String, ByVal DOB As Date, ByVal Ttype As Boolean)
If Ttype Then
Xrow("userid") = UId
Xrow("userfname") = fname
Xrow("userlname") = lname
Xrow("Userdate") = Format(CDate(DOB), "MM/dd/yyyy")
Else
Xrow("userfname") = fname
Xrow("userlname") = lname
Xrow("Userdate") = Format(CDate(DOB), "MM/dd/yyyy")
End If
End Sub
Function SaveComm(ByVal strSql As String) As OleDbCommand
Dim comm As New OleDbCommand(strSql, XConn)
comm.Parameters.Add("@UId", OleDbType.Char, 10, "userid")
comm.Parameters.Add("@FName", OleDbType.Char, 50, "userfname")
comm.Parameters.Add("@LName", OleDbType.Char, 50, "userlname")
comm.Parameters.Add("@DOB", OleDbType.DBTimeStamp, 8, "userdate")
Return comm
End Function
Public Sub SaveRecords(ByVal XRow As DataTable, ByVal Id As String, ByVal fname As String, ByVal lname As String, ByVal DOB As Date, ByVal Ttype As Boolean, ByVal Indx As Integer)
Dim SaveRow As DataRow
Dim EditRow As DataRow
If Ttype = True Then
SaveRow = XRow.NewRow
Equate(SaveRow, Id, fname, lname, DOB, True)
MyDstUser.Tables("UserTable").Rows.Add(SaveRow)
Dim MySaveCom As OleDbCommand = SaveComm("insert into users (userid, userfname, userlname, userdate) values " & _
"(@UId, @FName, @LName, @DOB)")
MyAdpUser.InsertCommand = MySaveCom
Else
EditRow = MyDstUser.Tables("usertable").Select("userid='" & Id & "'")(0)
EditRow.BeginEdit()
Equate(EditRow, Id, fname, lname, DOB, False)
EditRow.EndEdit()
Dim MyEditCom As OleDbCommand = SaveComm("update users set userfname=@FName, userlname=@LName, userdate=@DOB " & _
"where userid=@UId")
MyAdpUser.UpdateCommand = MyEditCom
End If
Try
MyAdpUser.Update(MyDstUser, "UserTable")
MsgBox("Update Complete")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
the function seem to be working just fine...
the problem is whenever i try to update a certain record it only goes as far as the dataset... the database doesnt get updated... the insert command works though.. i dont know what the problem is primarily because they both run through the same functions in my class...
hope you guys can help... tnx...
Public Sub Equate(ByVal Xrow As DataRow, ByVal UId As String, ByVal fname As String, ByVal lname As String, ByVal DOB As Date, ByVal Ttype As Boolean)
If Ttype Then
Xrow("userid") = UId
Xrow("userfname") = fname
Xrow("userlname") = lname
Xrow("Userdate") = Format(CDate(DOB), "MM/dd/yyyy")
Else
Xrow("userfname") = fname
Xrow("userlname") = lname
Xrow("Userdate") = Format(CDate(DOB), "MM/dd/yyyy")
End If
End Sub
Function SaveComm(ByVal strSql As String) As OleDbCommand
Dim comm As New OleDbCommand(strSql, XConn)
comm.Parameters.Add("@UId", OleDbType.Char, 10, "userid")
comm.Parameters.Add("@FName", OleDbType.Char, 50, "userfname")
comm.Parameters.Add("@LName", OleDbType.Char, 50, "userlname")
comm.Parameters.Add("@DOB", OleDbType.DBTimeStamp, 8, "userdate")
Return comm
End Function
Public Sub SaveRecords(ByVal XRow As DataTable, ByVal Id As String, ByVal fname As String, ByVal lname As String, ByVal DOB As Date, ByVal Ttype As Boolean, ByVal Indx As Integer)
Dim SaveRow As DataRow
Dim EditRow As DataRow
If Ttype = True Then
SaveRow = XRow.NewRow
Equate(SaveRow, Id, fname, lname, DOB, True)
MyDstUser.Tables("UserTable").Rows.Add(SaveRow)
Dim MySaveCom As OleDbCommand = SaveComm("insert into users (userid, userfname, userlname, userdate) values " & _
"(@UId, @FName, @LName, @DOB)")
MyAdpUser.InsertCommand = MySaveCom
Else
EditRow = MyDstUser.Tables("usertable").Select("userid='" & Id & "'")(0)
EditRow.BeginEdit()
Equate(EditRow, Id, fname, lname, DOB, False)
EditRow.EndEdit()
Dim MyEditCom As OleDbCommand = SaveComm("update users set userfname=@FName, userlname=@LName, userdate=@DOB " & _
"where userid=@UId")
MyAdpUser.UpdateCommand = MyEditCom
End If
Try
MyAdpUser.Update(MyDstUser, "UserTable")
MsgBox("Update Complete")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub