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

  • Thread starter Thread starter Luqman
  • Start date Start date
L

Luqman

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_Control1DataSet.Products)

Best Regards,

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

/claes
 
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
 
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


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
 
Thanks Jay.

Best Regards,

Luqman

Jay B. Harlow said:
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


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 said:
Yes, like this:
Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)
dr.Item("ProductID") = 123
dr.Item("ProductName") = "ABC"

/claes
 
Back
Top