Judt a quick Check

M

MadCrazyNewbie

Hi group,

Could i please ask somebodys opinion? Below is my code for my database
project. Would this seem like the best way to do it? I know there is many
ways to do it, and after all the help on this NG this is how far i`ve got.
Sorry i`ve asked so many questions, i just don`t want to start doing it
wrong from the start.

Anybody like to comment?

Many Many Thanks
MCN

Private Sub btnPasswordListsDelete_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsDelete.Click
If (Me.BindingContext(dsPasswordList, "PasswordList").Count > 0)
Then
Me.BindingContext(dsPasswordList,
"PasswordList").RemoveAt(Me.BindingContext(dsPasswordList,
"PasswordList").Position)
End If
End Sub

Private Sub btnPasswordListsAdd_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsAdd.Click
Try
Me.BindingContext(dsPasswordList,
"PasswordList").EndCurrentEdit()
Me.BindingContext(dsPasswordList, "PasswordList").AddNew()
Catch eEndEdit As System.Exception
System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
End Try
End Sub

Private Sub btnPasswordListsCancel_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsCancel.Click
Me.BindingContext(dsPasswordList,
"PasswordList").CancelCurrentEdit()
End Sub

Private Sub btnPasswordListsUpdate_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsUpdate.Click
Try
Dim objDataSetChanges As Excellence.NET.dsPasswordList = New
Excellence.NET.dsPasswordList()
Me.BindingContext(dsPasswordList,
"PasswordList").EndCurrentEdit()
objDataSetChanges = CType(dsPasswordList.GetChanges,
Excellence.NET.dsPasswordList)
If (Not (objDataSetChanges) Is Nothing) Then
Try
If (Not (dsPasswordList) Is Nothing) Then
Me.odcPasswordLists.Open()
odaDepartments.Update(dsPasswordList)
odaPasswordList.Update(dsPasswordList)
End If
Catch updateException As System.Exception
Throw updateException
Finally
Me.odcPasswordLists.Close()
End Try
End If
dsPasswordList.Merge(objDataSetChanges)
dsPasswordList.AcceptChanges()
Catch eUpdate As System.Exception
Throw eUpdate
End Try
Try
Catch eUpdate As System.Exception
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
End Try
End Sub
 
M

MadCrazyNewbie

Sorry forgot to add my Dataset Fill Code in:
Here it is:

Private Sub frmMainMenuPasswords_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
mlLoading = True
Try
dsPasswordList.EnforceConstraints = False
Try
Me.odcPasswordLists.Open()
Me.odaDepartments.Fill(dsPasswordList)
Me.odaPasswordList.Fill(dsPasswordList)
Catch fillException As System.Exception
Throw fillException
Finally
dsPasswordList.EnforceConstraints = True
Me.odcPasswordLists.Close()
End Try

Catch eLoad As System.Exception
System.Windows.Forms.MessageBox.Show(eLoad.Message)
Finally
mlLoading = False
End Try
End Sub

Ta
MCN
 
C

Cor

Hi Mad

Maybe it is good when you give some feed back on your messages, you have got
a lot of answers, but almost never you have given an feed back.

The one who gives an answer does it also to test his knowledge and without
an answer that is useless.

All text inline.
Private Sub btnPasswordListsDelete_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsDelete.Click
If (Me.BindingContext(dsPasswordList, "PasswordList").Count > 0)
Then
Me.BindingContext(dsPasswordList,
"PasswordList").RemoveAt(Me.BindingContext(dsPasswordList,
"PasswordList").Position)
End If
End Sub

Nicer is than that check for count > 0 here is to disable the delete button
in my opinion somehwere when the dataset is empty but it is not an important
one..

The removeAt deletes the row completly form the dataset and removes also the
delete information. It will never be updated. This has definatly to be a
DeleteAt when you want to update the dataset, I did it not use in this way
so for the rest I cannot see if it is correct. I thought the deleteAt was
not in the bindingcontext but is a member of the datarowcollection.

Private Sub btnPasswordListsAdd_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsAdd.Click
Try
Me.BindingContext(dsPasswordList,
"PasswordList").EndCurrentEdit()
Me.BindingContext(dsPasswordList, "PasswordList").AddNew()
Catch eEndEdit As System.Exception
System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
End Try
End Sub

Why endcurrentedit?
Private Sub btnPasswordListsCancel_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsCancel.Click
Me.BindingContext(dsPasswordList,
"PasswordList").CancelCurrentEdit()
End Sub

Private Sub btnPasswordListsUpdate_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsUpdate.Click
Try
Dim objDataSetChanges As Excellence.NET.dsPasswordList = New
Excellence.NET.dsPasswordList()
Me.BindingContext(dsPasswordList,
"PasswordList").EndCurrentEdit()
objDataSetChanges = CType(dsPasswordList.GetChanges,
Excellence.NET.dsPasswordList)
If (Not (objDataSetChanges) Is Nothing) Then
Try
If (Not (dsPasswordList) Is Nothing) Then
Me.odcPasswordLists.Open()
odaDepartments.Update(dsPasswordList)
odaPasswordList.Update(dsPasswordList)
End If
Catch updateException As System.Exception
Throw updateException
Finally
Me.odcPasswordLists.Close()
End Try
End If
dsPasswordList.Merge(objDataSetChanges)
dsPasswordList.AcceptChanges()
Catch eUpdate As System.Exception
Throw eUpdate
End Try
Try
Catch eUpdate As System.Exception
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
End Try
End Sub
In my opinion is this much to difficult, you are not using an middle tier.
You are direct on the form, so why you do a merge and why 2 datasets, that
will only create concurrency errors in this way I suspect.

I try to do some corrections below, I cannot see what are the datasets but
there can not needed much more.

Private Sub btnPasswordListsUpdate_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsUpdate.Click
Me.BindingContext(dsPasswordList,
"PasswordList").EndCurrentEdit()
Try
If dsPasswordList.haschanges Then
odaPasswordList.Update(dsPasswordList)
End If
Catch eUpdate As System.Exception
MessageBox.Show(eUpdate.Message)
End Try
Try
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top