N
No_So_Clever
Hi There,
Hope Somebody dosn`t mind Helping a Newbie?
I have the Follwoing Code:
Private Sub frmSystemUsers_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'File Datasets
Try
dsSystemUsers.EnforceConstraints = False
Try
Me.odcSystemUsers.Open()
odaSystemUsers.Fill(dsSystemUsers)
cmSystemUsers = DirectCast(BindingContext(dvSystemUsers), CurrencyManager)
mlLoading = True
Catch fillException As System.Exception
Throw fillException
Finally
Me.odcSystemUsers.Close()
End Try
Catch eLoad As System.Exception
System.Windows.Forms.MessageBox.Show(eLoad.Message)
Finally
mlLoading = False
End Try
'End of Fill Datasets
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
cmSystemUsers.AddNew()
txtFirstname.Enabled = True
txtSurname.Enabled = True
txtUsername.Enabled = True
txtPassword.Enabled = True
End Sub
Private Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAccept.Click
If txtFirstname.Text = "" Then
ValidDataMessage = "First Name Required"
txtFirstname.Focus()
ElseIf txtSurname.Text = "" Then
ValidDataMessage = "Surname Required"
txtSurname.Focus()
ElseIf txtUsername.Text = "" Then
ValidDataMessage = "Username Required"
txtUsername.Focus()
ElseIf txtPassword.Text = "" Then
ValidDataMessage = "Password Required"
txtPassword.Focus()
If ValidDataMessage = "" Then
If MessageBox.Show("This Will Save All Changes - Are You Sure?", "Warning!",
MessageBoxButtons.OKCancel) = DialogResult.OK Then
cmSystemUsers.EndCurrentEdit()
If dsSystemUsers.HasChanges Then
odaSystemUsers.Update(dsSystemUsers)
dsSystemUsers.Clear()
odaSystemUsers.Fill(dsSystemUsers)
End If
Else
End If
MessageBox.Show(ValidDataMessage, "Data Entry Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End If
End If
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Dim DeleteResult As DialogResult = MessageBox.Show("Delete " &
txtUsername.Text & " ?", "Warning!", MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
If DeleteResult = DialogResult.Yes Then
Me.dvSystemUsers(cmSystemUsers.Position).Delete()
End If
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEdit.Click
txtFirstname.Enabled = True
txtSurname.Enabled = True
txtUsername.Enabled = True
txtPassword.Enabled = True
End Sub
Private Sub btnCancelChanges_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCancelChanges.Click
If MessageBox.Show("This Will Cancel All Changes - Are You Sure?",
"Warning!", MessageBoxButtons.OKCancel) = DialogResult.OK Then
cmSystemUsers.CancelCurrentEdit()
End If
txtFirstname.Enabled = False
txtSurname.Enabled = False
txtUsername.Enabled = False
txtPassword.Enabled = False
End Sub
End Class
First Question - Am I writing my code the correct way for a Database
Application, or am I going about it totally the Wrong Way?
Second Question is - Why I try and click my Update Button, it dosn`t Update
the Data to my Database. It Adds a Row but with just Blank Data
Third Question - When I delete a Row, It deletes it on Screen but dosn`t
Update My Database Again
Sorry for been sooooooo Stupid but like I said Im a newbie thats confused,
I`ve search the Net but got even more confused because it seems there is so
many ways of doing things.
Hope omebody dosn`t mind Helping out?
Many Thanks
NSC
Hope Somebody dosn`t mind Helping a Newbie?
I have the Follwoing Code:
Private Sub frmSystemUsers_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'File Datasets
Try
dsSystemUsers.EnforceConstraints = False
Try
Me.odcSystemUsers.Open()
odaSystemUsers.Fill(dsSystemUsers)
cmSystemUsers = DirectCast(BindingContext(dvSystemUsers), CurrencyManager)
mlLoading = True
Catch fillException As System.Exception
Throw fillException
Finally
Me.odcSystemUsers.Close()
End Try
Catch eLoad As System.Exception
System.Windows.Forms.MessageBox.Show(eLoad.Message)
Finally
mlLoading = False
End Try
'End of Fill Datasets
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
cmSystemUsers.AddNew()
txtFirstname.Enabled = True
txtSurname.Enabled = True
txtUsername.Enabled = True
txtPassword.Enabled = True
End Sub
Private Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAccept.Click
If txtFirstname.Text = "" Then
ValidDataMessage = "First Name Required"
txtFirstname.Focus()
ElseIf txtSurname.Text = "" Then
ValidDataMessage = "Surname Required"
txtSurname.Focus()
ElseIf txtUsername.Text = "" Then
ValidDataMessage = "Username Required"
txtUsername.Focus()
ElseIf txtPassword.Text = "" Then
ValidDataMessage = "Password Required"
txtPassword.Focus()
If ValidDataMessage = "" Then
If MessageBox.Show("This Will Save All Changes - Are You Sure?", "Warning!",
MessageBoxButtons.OKCancel) = DialogResult.OK Then
cmSystemUsers.EndCurrentEdit()
If dsSystemUsers.HasChanges Then
odaSystemUsers.Update(dsSystemUsers)
dsSystemUsers.Clear()
odaSystemUsers.Fill(dsSystemUsers)
End If
Else
End If
MessageBox.Show(ValidDataMessage, "Data Entry Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End If
End If
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Dim DeleteResult As DialogResult = MessageBox.Show("Delete " &
txtUsername.Text & " ?", "Warning!", MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
If DeleteResult = DialogResult.Yes Then
Me.dvSystemUsers(cmSystemUsers.Position).Delete()
End If
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEdit.Click
txtFirstname.Enabled = True
txtSurname.Enabled = True
txtUsername.Enabled = True
txtPassword.Enabled = True
End Sub
Private Sub btnCancelChanges_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCancelChanges.Click
If MessageBox.Show("This Will Cancel All Changes - Are You Sure?",
"Warning!", MessageBoxButtons.OKCancel) = DialogResult.OK Then
cmSystemUsers.CancelCurrentEdit()
End If
txtFirstname.Enabled = False
txtSurname.Enabled = False
txtUsername.Enabled = False
txtPassword.Enabled = False
End Sub
End Class
First Question - Am I writing my code the correct way for a Database
Application, or am I going about it totally the Wrong Way?
Second Question is - Why I try and click my Update Button, it dosn`t Update
the Data to my Database. It Adds a Row but with just Blank Data
Third Question - When I delete a Row, It deletes it on Screen but dosn`t
Update My Database Again
Sorry for been sooooooo Stupid but like I said Im a newbie thats confused,
I`ve search the Net but got even more confused because it seems there is so
many ways of doing things.
Hope omebody dosn`t mind Helping out?
Many Thanks
NSC