Private Sub cmdsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsave.Click
Dim Nrow As DataRow
Dim Listctr, i As Integer
Dim NameStr As String
If CheckText() <> False Then
If AddFlag = True Then
Listctr = lvw1.Items.Count
Nrow = NewTable.NewRow()
MyClassObj.SaveRecords(Nrow, Trim(txtid.Text), Trim(txtfname.Text), Trim(txtlname.Text), CDate(txtdate.Text), True)
lvw1.Items.Add(txtid.Text)
NameStr = Trim(txtfname.Text.ToString) & " " & Trim(txtlname.Text.ToString)
lvw1.Items(Listctr).SubItems.Add(NameStr)
lvw1.Items(Listctr).SubItems.Add(Format(CDate(txtdate.Text), "MM/dd/yyyy"))
Else
Nrow = NewTable.Select("userid='" & Trim(txtid.Text))(0)
MyClassObj.SaveRecords(Nrow, Trim(txtid.Text), Trim(txtfname.Text), Trim(txtlname.Text), CDate(txtdate.Text), False)
' Listview update not yet done
End If
NewTable.AcceptChanges()
VButs(True)
End If
Public Sub Equate(ByVal Xrow As DataRow, ByVal Id As String, ByVal fname As String, ByVal lname As String, ByVal DOB As Date, ByVal Ttype As Boolean)
If Ttype Then
Xrow("userid") = Id
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.Integer, 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 DataRow, ByVal Id As String, ByVal fname As String, ByVal lname As String, ByVal DOB As Date, ByVal Ttype As Boolean)
Dim SaveRow As DataRow
If Ttype = True Then
SaveRow = XRow
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
XRow.BeginEdit()
Equate(SaveRow, Id, fname, lname, DOB, False)
XRow.EndEdit()
Dim MyEditCom As OleDbCommand = SaveComm("update users set userfname=@FName, userlname=@LName, userdate=@DOB " & _
"where userid=@UId")
MyAdpUser.UpdateCommand = MyEditCom
End If
MyAdpUser.Update(MyDstUser, "UserTable")
MsgBox("Update Complete")
End Sub
just try to trace through these lines... its kinda hard to explain.. but this works in both adding and editing...