DataRow - How To?

M

MadCrazyNewbie

Hey Group,

I wondered if somebody would be so kind as to help me? Im having trouble
with DataViews and DataRows:(

I just don`t understand, so I wondered if somebody would be so kind enought
to modify my code below to include Datarows and Dataviews and maybe explain
a little aswell?

Many Thanks
Regards
MCN

Private Sub frmMainMenuPasswords_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load

cmDsPasswordList = BindingContext(dsPasswordList, "PasswordList")
mlLoading = True
'Start of Fill Datasets
Try
dsPasswordList.EnforceConstraints = False
dsArcirisUsers.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
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
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
End If
End Sub
 
O

One Handed Man \( OHM - Terry Burns \)

There is a plethora of code beneath. I suggest you are more succinct with
you question. What dont you understand about DataRow and DataView.?

Rows isa collection of DataRows in a Table, A tables DataView is a view of
that Table, there is also a DataView class in its own right.

Can you try again now ?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

MadCrazyNewbie said:
Hey Group,

I wondered if somebody would be so kind as to help me? Im having trouble
with DataViews and DataRows:(

I just don`t understand, so I wondered if somebody would be so kind enought
to modify my code below to include Datarows and Dataviews and maybe explain
a little aswell?

Many Thanks
Regards
MCN


Private Sub frmMainMenuPasswords_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load

cmDsPasswordList = BindingContext(dsPasswordList, "PasswordList")
mlLoading = True
'Start of Fill Datasets
Try
dsPasswordList.EnforceConstraints = False
dsArcirisUsers.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
 
C

Cor Ligthert

Simon,

It is real hard to answer, however in that "document part" of your
documentation is a very good to see how the dataview is working.

And take some time for it, this is not something done in an hour when you
are not used to it, and even than probably it will take some time.

I suggest that you first have a look at that.

Cor
 
M

MadCrazyNewbie

Cor,

On my FaxCopiers form im trying to do:

dvfaxs = New (dsFaxs.Faxs)

is this right? It tell me that D:\Excellence.Net\MainMenuPasswords.vb(1355):
Reference to a non-shared member requires an object reference.

dvfaxs = New Dataview(dsFaxs.tables(0)) it tell me the same

I`ve also tryed:

dvFaxs = New Dataview(dsFaxs.Departments) again the same error.

Could you point me in the right direction?

Cheers
MCN(Si)
 
C

Cor Ligthert

Simon,

I get the idea that you are consequently giving (change) the name of the
actual dataset the same name as the dataset.class that is generated by the
dataadapter.

That makes it difficult to see what you are doing.

You can see that in your dataset properties, give them both a different
name, that will make things easier.

With the class you do
dataset1.mytablename

With the dataset you do
dataset11.tables(0)

Cor
 
M

MadCrazyNewbie

Cor,

Sorry are you saying name the Datasetname and DatasetDesign name different?

Cheers
Si
 
M

MadCrazyNewbie

Also Cor,

What does:
New DataView(dsPasswordList.Tables(0)) - Mean?

When im building a Datavies will i mees to build one for each Relationship
or just for the dataset?

Ie - New DataView(dsPasswordList.Tables(0)) or

New DataView(dsPasswordList.Departments(0))
New DataView(dsPasswordList.Sites(0))
New DataView(dsPasswordList.User(0)) etc etc

If you get my meaning?

Cheers
MCN
 
C

Cor Ligthert

Simon,

I get always mixed up with a strongly typed dataset (that is generated from
the dataadapter).
New DataView(dsPasswordList.Tables(0)) - Mean?

Normal it can be
dim dv as dataview
dv = new dataview(dsPasswordList1.Tables(0))
what mean use for the dv the actual dataset dsPasswordList1 and from that
the first table

A dataview does not make relations. However when you use
dv.rowfilter = "Whatever = WhatIWant"
Then you filter it, what is when you want all the rows in your dataset that
has the ident it gives you all rows that are related to that ident (what you
can see of course as a relation).

When you use a strongly typed dataset you never use that tableindex because
it gives you directly the table.

(A strongly typed dataset is just a name for a class, when you open in your
solution explorere "show all files" you can see them when you open the +
before your datasets.)

I hope this helps sofar?

Cor
 
M

MadCrazyNewbie

Cor,

I think im beginning to understand now, however when i do:

dvPasswordlist = new dataview(dsPasswordList.Tables(0)) or even
dvPasswordlist = new dataview(dsPasswordList1.Tables(0))

I get a error saying : D:\Excellence.Net\MainMenuPasswords.vb(1355): Value
of type 'System.Data.DataView' cannot be converted to '1-dimensional array
of System.Data.DataView'.

Any Ideas?

Cheers
MCN
 
C

Cor Ligthert

Simon,

I am thinking and thinking and really cannot understand this.

Maybe I get the light tomorrow

Cor
 
M

MadCrazyNewbie

Hey cor,

Sorry to trouble you again i`ve been playing with the dataview thing, sorry
no matter which way i try and do it it tells me:

dvPasswordlist = new dataview(dsPasswordList.Tables(0)) or even
dvPasswordlist = new dataview(dsPasswordList1.Tables(0))

A Error saying : D:\Excellence.Net\MainMenuPasswords.vb(1355): Value
of type 'System.Data.DataView' cannot be converted to '1-dimensional array
of System.Data.DataView'.

Any Ideas?

Cheers
MCN
 
C

Cor Ligthert

Simon,

I really do not know, I find it so strange, can you try, just to try
dvPasswordlist = new dataview(dsPasswordList.Tables(0)) or even
dvPasswordlist = new dataview(dsPasswordList1.Tables(0))
dim dv as new dataview(dsPasswordList.Tables(0))
or/and
dim dv as new dataview(dsPasswordList1.Tables(0))

Cor
 
M

MadCrazyNewbie

Hey Cor,

Dim dvPasswordList As New DataView(dsPasswordList.Tables(0))
Works a treat, no more error:) i`ll carry on ploffing through it all now,
i`ve just ordered MSDN so hopefully i should be able to use that as a good
reference:)

Cheers Cor
MCN
 
J

Jay B. Harlow [MVP - Outlook]

MCN,
is this right? It tell me that D:\Excellence.Net\MainMenuPasswords.vb(1355):
Reference to a non-shared member requires an object reference.

Indicates that you are attempting to use an Instance field from a Shared
method.

Something like:

Public Class MainMenuPasswords

Public dsFaxs As DataSet

Public Shared Sub BadCode()

dvFaxs = New Dataview(dsFaxs.Departments) again the same error.

End Sub

Notice that dsFaxs does not have Shared in the declaration, where as BadCode
does have Shared, the code in BadCode, does not know which instance of
MainMenuPasswords to use.

Hope this helps
Jay
 

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

DBNUL Errors Continued 4
Judt a quick Check 2
Null & DBNULL Problems 4
Ado - Driving me Nuts 4
Anoying Problem 6
Litle Problem Help Plz 2
Database Records Represantation Problem ? ? ? 1
Debugging Error 1

Top