Home All Groups Group Topic Archive Search About

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

Author
29 Mar 2006 8:16 AM
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

Author
29 Mar 2006 2:12 PM
Claes Bergefall
Yes, like this:
Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow)
dr.Item("ProductID") = 123
dr.Item("ProductName") = "ABC"

   /claes

Show quoteHide quote
"Luqman" <pearls***@cyber.net.pk> wrote in message
news:euZTpiwUGHA.5552@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_Control1DataSet.Products)
>
> Best Regards,
>
> Luqman
>
>
Author
29 Mar 2006 3:05 PM
Luqman
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





Show quoteHide quote
"Claes Bergefall" <claes.bergefall@nospam.nospam> wrote in message news:eDWhFqzUGHA.196@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" <pearls***@cyber.net.pk> wrote in message
> news:euZTpiwUGHA.5552@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_Control1DataSet.Products)
>>
>> Best Regards,
>>
>> Luqman
>>
>>
>
>
Author
30 Mar 2006 1:34 PM
Jay B. Harlow [MVP - Outlook]
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" <pearls***@cyber.net.pk> wrote in message
news:ukprRM0UGHA.5248@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





Show quoteHide quote
"Claes Bergefall" <claes.bergefall@nospam.nospam> wrote in message
news:eDWhFqzUGHA.196@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" <pearls***@cyber.net.pk> wrote in message
> news:euZTpiwUGHA.5552@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_Control1DataSet.Products)
>>
>> Best Regards,
>>
>> Luqman
>>
>>
>
>
Author
31 Mar 2006 6:21 AM
Luqman
Thanks Jay.

Best Regards,

Luqman

Show quoteHide quote
"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> wrote in
message news:uCVM06$UGHA.4772@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" <pearls***@cyber.net.pk> wrote in message
> news:ukprRM0UGHA.5248@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" <claes.bergefall@nospam.nospam> wrote in message
> news:eDWhFqzUGHA.196@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" <pearls***@cyber.net.pk> wrote in message
> > news:euZTpiwUGHA.5552@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_Control1DataSet.Products)
> >>
> >> Best Regards,
> >>
> >> Luqman
> >>
> >>
> >
> >
>
>