DBNUL Errors Continued

  • Thread starter Thread starter MadCrazyNewbie
  • Start date Start date
M

MadCrazyNewbie

Hey Group,

Please bare with me ehile I try and explain, i think i maybe on the wrong
track but this is driving me crazy now:(

I have the following code:

Private Sub frmMainMenuPasswords_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
odcPasswordLists.ConnectionString = Connection.String

cmDsPasswordList = BindingContext(dsPasswordList, "PasswordList")
mlLoading = True
'Start of Fill Datasets
Try
dsPasswordList.EnforceConstraints = False
Try
Me.odcPasswordLists.Open()
'Fill Password Lists Datasets
Me.odaDepartments.Fill(dsPasswordList)
Me.odaPasswordList.Fill(dsPasswordList)
Catch fillException As System.Exception
Throw fillException
Finally
'To be enabled if Dataset Bindings Fail - Enabling will
cause BIG Datasets
'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 of Fill Datasets
End Sub

'Start of Position Changed Code - Password Lists
Private Sub cmDsPasswordList_PositionChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles cmDsPasswordList.PositionChanged
DsPasswordList_PositionChanged()
End Sub

Private Sub cboPasswordListsDepartment_SelectedIndexChanged(ByVal sender
As Object, ByVal e As System.EventArgs) Handles
cboPasswordListsDepartment.SelectedIndexChanged
Me.BindingContext(dsPasswordList, "PasswordList").EndCurrentEdit()
If Me.BindingContext(dsPasswordList, "PasswordList").Position <> -1
And Not mlLoading Then

dsPasswordList.PasswordList.Rows(Me.BindingContext(dsPasswordList,
"PasswordList").Position).Item("DepartmentID") =
Me.cboPasswordListsDepartment.SelectedValue
End If
End Sub

Private Sub DsPasswordList_PositionChanged()
Me.BindingContext(dsPasswordList, "PasswordList").EndCurrentEdit()
If Me.BindingContext(dsPasswordList, "PasswordList").Position <> -1
And Not mlLoading Then
Me.cboPasswordListsDepartment.SelectedValue =
dsPasswordList.PasswordList.Rows(Me.BindingContext(dsPasswordList,
"PasswordList").Position).Item("DepartmentID")
End If
End Sub
'End of Position Changed Code - Password Lists

'PasswordLists Code Start
Private Sub btnPasswordListsDelete_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsDelete.Click
If MessageBox.Show("Are Your Sure You Want To Delete?",
"WARNING!!!!", MessageBoxButtons.OKCancel) = DialogResult.OK Then
If (Me.BindingContext(dsPasswordList, "PasswordList").Count > 0)
Then
Me.BindingContext(dsPasswordList,
"PasswordList").RemoveAt(Me.BindingContext(dsPasswordList,
"PasswordList").Position)
End If
End If
End Sub

Private Sub btnPasswordListsAdd_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsAdd.Click
'Reset Combo Box`s - Select Index Twice due to M$ Bug
cboPasswordListsDepartment.Text = ""
cboPasswordListsDepartment.SelectedIndex = -1
cboPasswordListsDepartment.SelectedIndex = -1

txtPasswordListsAccessLevel.Enabled = True
txtPasswordListsID.Enabled = True
txtPasswordListsNotes.Enabled = True
txtPasswordListsPassword.Enabled = True
txtPasswordListsPrimaryUse.Enabled = True
txtPasswordListsPrimaryUser.Enabled = True
txtPasswordListsSystem.Enabled = True
txtPasswordListsUsername.Enabled = True
txtPasswordListsWebAddress.Enabled = True
dtpPasswordLists.Enabled = True
cboPasswordListsDepartment.Enabled = True
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()
txtPasswordListsAccessLevel.Enabled = False
txtPasswordListsID.Enabled = False
txtPasswordListsNotes.Enabled = False
txtPasswordListsPassword.Enabled = False
txtPasswordListsPrimaryUse.Enabled = False
txtPasswordListsPrimaryUser.Enabled = False
txtPasswordListsSystem.Enabled = False
txtPasswordListsUsername.Enabled = False
txtPasswordListsWebAddress.Enabled = False
dtpPasswordLists.Enabled = False
cboPasswordListsDepartment.Enabled = False
End Sub

Private Sub btnPasswordListsUpdate_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsUpdate.Click
If MessageBox.Show("Are Your Sure You Want To Save Changes?",
"WARNING!!!!", MessageBoxButtons.OKCancel) = DialogResult.OK Then
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
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
End Try
txtPasswordListsAccessLevel.Enabled = False
txtPasswordListsID.Enabled = False
txtPasswordListsNotes.Enabled = False
txtPasswordListsPassword.Enabled = False
txtPasswordListsPrimaryUse.Enabled = False
txtPasswordListsPrimaryUser.Enabled = False
txtPasswordListsSystem.Enabled = False
txtPasswordListsUsername.Enabled = False
txtPasswordListsWebAddress.Enabled = False
dtpPasswordLists.Enabled = False
cboPasswordListsDepartment.Enabled = False
End If
End Sub

Private Sub btnPasswordListsEdit_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPasswordListsEdit.Click
txtPasswordListsAccessLevel.Enabled = True
txtPasswordListsID.Enabled = True
txtPasswordListsNotes.Enabled = True
txtPasswordListsPassword.Enabled = True
txtPasswordListsPrimaryUse.Enabled = True
txtPasswordListsPrimaryUser.Enabled = True
txtPasswordListsSystem.Enabled = True
txtPasswordListsUsername.Enabled = True
txtPasswordListsWebAddress.Enabled = True
dtpPasswordLists.Enabled = True
cboPasswordListsDepartment.Enabled = True
End Sub
'PasswordLists Code Finish

When I try to run my Add code it errors on:

dsPasswordList.PasswordList.Rows(Me.BindingContext(dsPasswordList,
"PasswordList").Position).Item("DepartmentID") =
Me.cboPasswordListsDepartment.SelectedValue

And tells me it cannot user NULL and to use DBNULL instead so i put:

dsPasswordList.PasswordList.Rows(Me.BindingContext(dsPasswordList,
"PasswordList").Position).Item("DepartmentID") =
Me.cboPasswordListsDepartment.SelectedValue = system.DBNULL.value - but it
fails to compile and tells me:

D:\Excellence.Net\MainMenuPasswords.vb(1390): Operator '=' is not defined
for types 'System.Object' and 'System.DBNull'. Use 'Is' operator to compare
two reference types.

If I remove the following code from my project:

'Reset Combo Box`s - Select Index Twice due to M$ Bug
cboPasswordListsDepartment.Text = ""
cboPasswordListsDepartment.SelectedIndex = -1
cboPasswordListsDepartment.SelectedIndex = -1

It lets me add a row but then gives me a Concurrency Violation When I run my
Update Code.

Anybody got any Ideas?

Many Thanks and Sorry for the long Post
Regards
MCN
 
Simon,

I repeat, I thought you are using the wrong displayvalue in the comboboxes.
(Not visible in this part of your code because you have binded it using the
designer)

That returns a DBNull value and therefore you get this error. However
correcting that as described does not correct the problem.

However just guessing

Cor
 
Sorry Cor,

Think my newsstream is well out of date, its so slow so im not getting the
posts stright away:(

What should the value be?

I`ve been looking at the errors, and also at the DataRows that I need to add
in, but im lost, as per my e-mail:(

I`ve been playing but keep seeming to make things worse:(

Hope you can help
Cheers
Simon
 
I wrote that I do not believe that the way you are using it works, Because
you are using as displaymember something from a database table, which has a
reference in your access database, however you are loading it in your
selects without any reference as a completly seperated table.

So I think the most easiest way for this (because it is a small database)
can be using that same dataview approach as with the documents.

Cor
 
Cor,

Im looking at the DataRow view just having trouble with it, i`ll get
something together and i`ll give you a shout if i get stuck, i`ve noticed
from reading the datarow is very comple to, next will be the concurrecny:(

Cheers Cor
MCN(Si)
 
Back
Top