By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,326 Members | 881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,326 IT Pros & Developers. It's quick & easy.

DataRow - How To?

P: n/a
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
CODE START <<<<


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(By Val 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(dsPassw ordList,
"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.Mess age)
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.Messa ge)
End Try
End If
End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
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" <te**@nospam.com> wrote in message
news:SB********************@karoo.co.uk...
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
> CODE START <<<<

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(By Val 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(dsPassw ordList,
"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.Mess age)
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.Messa ge)
End Try
End If
End Sub

Nov 21 '05 #2

P: n/a
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

Nov 21 '05 #3

P: n/a
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)
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O7**************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #4

P: n/a
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
Nov 21 '05 #5

P: n/a
Cor,

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

Cheers
Si

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ui**************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #6

P: n/a
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

"MadCrazyNewbie" <te**@nospam.com> wrote in message
news:u4********************@karoo.co.uk...
Cor,

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

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ui**************@TK2MSFTNGP10.phx.gbl...
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


Nov 21 '05 #7

P: n/a
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

Nov 21 '05 #8

P: n/a
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

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uK**************@TK2MSFTNGP11.phx.gbl...
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


Nov 21 '05 #9

P: n/a
Simon,

I am thinking and thinking and really cannot understand this.

Maybe I get the light tomorrow

Cor
Nov 21 '05 #10

P: n/a
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

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Oo**************@TK2MSFTNGP11.phx.gbl...
Simon,

I am thinking and thinking and really cannot understand this.

Maybe I get the light tomorrow

Cor

Nov 21 '05 #11

P: n/a
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
Nov 21 '05 #12

P: n/a
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

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Om*************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #13

P: n/a
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

"MadCrazyNewbie" <te**@nospam.com> wrote in message
news:YH********************@karoo.co.uk... 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)
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O7**************@TK2MSFTNGP10.phx.gbl...
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


Nov 21 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.