I have a dataTable with only one unique record and want to bind this to
a couple of textboxes in a form, so that when a user changes a value,
it's eventually reflected back to the database.
The dataset I use is 'untyped' - so I'm not able to do a typed databind,
and this is causing me great troubles... Does anyone know how to do this?
The code:
tbTagno.DataBindings.Add("Text",dtTagDetails.Rows[0].ItemArray[0].ToString(),null);
works in so far as displaying the read database value from the dataTable
dtTagDetails, but since the third parameter is null, nothing is sent
back from the textbox naturally. And I can't find any way to set ut the
third parameter correctly!
tbTagDesc.DataBindings.Add("Text",dtTagDetails.Rows[0].ItemArray[2].ToString(),"dtTagDetails.Columns[2].ColumnName");
does not compile of course.
(As a workaround, I've tried manuall copying values back and forth on
load and save, the code:
tbTagno.Text = dtTagDetails.Rows[0].ItemArray[0].ToString();
works, i.e. the form field is updated with the value from the database
row, but when trying to do a:
dtTagDetails.Rows[0].ItemArray[2] = tbTagDesc.Text;
or a:
daTagDetails.ds.Tables[0].Rows[0].ItemArray[2] = tbTagDesc.Text;
none of the dataTable or dataAdapter arrays are changed... they seem to
be locked with their original database value....
Anyone got any ideas on untyped datasets? Am I missing something vital
in using these? Do I need to use currencyManager even though I only have
one row in my dataTable?
Regards,
-Haakon-
the
Alexander Shirshov - 20 Mar 2005 16:51 GMT
Try this:
tbTagDesc.DataBindings.Add("Text", dtTagDetails, "ColumnName");
HTH,
Alexander
>I have a dataTable with only one unique record and want to bind this to a
>couple of textboxes in a form, so that when a user changes a value, it's
[quoted text clipped - 39 lines]
> -Haakon-
> the
Håkon Eide - 21 Mar 2005 10:30 GMT
Tried that, doesn't work. However, this works:
tbTagDesc.DataBindings.Add("Text", dtTagDetails,
dtTagDetails.Columns[2].ColumnName);
..and when I then include a
this.BindingContext[dtTagDetails].EndCurrentEdit();
when user click's "Save" - the data is updated and everything works!
Maybe this can help others struggling with untyped datasets....
Regards,
-Haakon-
> Try this:
>
> tbTagDesc.DataBindings.Add("Text", dtTagDetails, "ColumnName");
>
> HTH,
> Alexander
Stanley - 21 Mar 2005 14:08 GMT
Change it to:
tbTagDesc.DataBindings.Add(New
Binding("Text",dtTagDetails,Columns[2].ColumnName))
This is assuming that dtTagDetails is a datatable.
-Stanley
> Tried that, doesn't work. However, this works:
>
[quoted text clipped - 17 lines]
>> HTH,
>> Alexander