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

Is it possible to use Field Names instead of Item(0) with Data Row using VB.Net 2005 ?

P: n/a
Hi,

Is it possible to use Field Names with Data Row.

for example:

Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)
dr.ProductID=123
dr.ProductName="ABC"
Me.ProductsBindingSource.EndEdit()
Me.ProductsTableAdapter.Update(Me.Inventory_Contro l1DataSet.Products)

Best Regards,

Luqman
Mar 29 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Yes, like this:
Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)
dr.Item("ProductID") = 123
dr.Item("ProductName") = "ABC"

/claes

"Luqman" <pe*******@cyber.net.pk> wrote in message
news:eu**************@TK2MSFTNGP14.phx.gbl...
Hi,

Is it possible to use Field Names with Data Row.

for example:

Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)
dr.ProductID=123
dr.ProductName="ABC"
Me.ProductsBindingSource.EndEdit()
Me.ProductsTableAdapter.Update(Me.Inventory_Contro l1DataSet.Products)

Best Regards,

Luqman

Mar 29 '06 #2

P: n/a
Hi,

following line giving error.

Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)

System.InvalidCastException was unhandled
Message="Unable to cast object of type 'System.Data.DataRowView' to type 'System.Data.DataRow'."
Any idea please ?

Best Regards,

Luqman

"Claes Bergefall" <cl*************@nospam.nospam> wrote in message news:eD*************@TK2MSFTNGP10.phx.gbl...
Yes, like this:
Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)
dr.Item("ProductID") = 123
dr.Item("ProductName") = "ABC"

/claes

"Luqman" <pe*******@cyber.net.pk> wrote in message
news:eu**************@TK2MSFTNGP14.phx.gbl...
Hi,

Is it possible to use Field Names with Data Row.

for example:

Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)
dr.ProductID=123
dr.ProductName="ABC"
Me.ProductsBindingSource.EndEdit()
Me.ProductsTableAdapter.Update(Me.Inventory_Contro l1DataSet.Products)

Best Regards,

Luqman



Mar 29 '06 #3

P: n/a
Luqman,
BindingSource.Current returns a DataRowView instead of a DataRow, change
your cast to be:

Dim dr As DataRowView = CType(Me.ProductsBindingSource.Current,
DataRowView)

DataRowView & DataRow as analogous to DataView & DataTable.

If you want the actual DataRow, you can use the DataRowView.Row property:

Dim dr As DataRow = CType(Me.ProductsBindingSource.Current,
DataRowView).Row

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Luqman" <pe*******@cyber.net.pk> wrote in message
news:uk**************@TK2MSFTNGP10.phx.gbl...
Hi,

following line giving error.

Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)

System.InvalidCastException was unhandled
Message="Unable to cast object of type 'System.Data.DataRowView' to type
'System.Data.DataRow'."
Any idea please ?

Best Regards,

Luqman

"Claes Bergefall" <cl*************@nospam.nospam> wrote in message
news:eD*************@TK2MSFTNGP10.phx.gbl...
Yes, like this:
Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)
dr.Item("ProductID") = 123
dr.Item("ProductName") = "ABC"

/claes

"Luqman" <pe*******@cyber.net.pk> wrote in message
news:eu**************@TK2MSFTNGP14.phx.gbl...
Hi,

Is it possible to use Field Names with Data Row.

for example:

Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)
dr.ProductID=123
dr.ProductName="ABC"
Me.ProductsBindingSource.EndEdit()
Me.ProductsTableAdapter.Update(Me.Inventory_Contro l1DataSet.Products)

Best Regards,

Luqman


Mar 30 '06 #4

P: n/a
Thanks Jay.

Best Regards,

Luqman

"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> wrote in
message news:uC**************@TK2MSFTNGP14.phx.gbl...
Luqman,
BindingSource.Current returns a DataRowView instead of a DataRow, change
your cast to be:

Dim dr As DataRowView = CType(Me.ProductsBindingSource.Current,
DataRowView)

DataRowView & DataRow as analogous to DataView & DataTable.

If you want the actual DataRow, you can use the DataRowView.Row property:

Dim dr As DataRow = CType(Me.ProductsBindingSource.Current,
DataRowView).Row

--
Hope this helps
Jay [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Luqman" <pe*******@cyber.net.pk> wrote in message
news:uk**************@TK2MSFTNGP10.phx.gbl...
Hi,

following line giving error.

Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)

System.InvalidCastException was unhandled
Message="Unable to cast object of type 'System.Data.DataRowView' to type
'System.Data.DataRow'."
Any idea please ?

Best Regards,

Luqman

"Claes Bergefall" <cl*************@nospam.nospam> wrote in message
news:eD*************@TK2MSFTNGP10.phx.gbl...
Yes, like this:
Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)
dr.Item("ProductID") = 123
dr.Item("ProductName") = "ABC"

/claes

"Luqman" <pe*******@cyber.net.pk> wrote in message
news:eu**************@TK2MSFTNGP14.phx.gbl...
Hi,

Is it possible to use Field Names with Data Row.

for example:

Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)
dr.ProductID=123
dr.ProductName="ABC"
Me.ProductsBindingSource.EndEdit()
Me.ProductsTableAdapter.Update(Me.Inventory_Contro l1DataSet.Products)

Best Regards,

Luqman



Mar 31 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.