How to Bind Column with TextBox
Dear All,
I want to bind a textbox with a column and then move forward and backward in dataset. so please tell me how to bind a column with a textbox, please write complete code.
ds =newDataSet();
adapter =newSqlDataAdapter("select * from a", connection);
adapter.Fill(ds,"a");
[694 byte] By [
jehan] at [2007-12-23]
this.theTextBox.DataBindings.Add("Text", ds.Tables[0].DefaultView, "columnName");
where ds is your datasource (datatable/dataset)
does this help?
ahmedilyas wrote: |
| this.theTextBox.DataBindings.Add("Text", ds.Tables[0].DefaultView, "columnName"); where ds is your datasource (datatable/dataset) does this help? |
|
SqlDataAdapter
a = new SqlDataAdapter
(
"select name from question;", connection);DataSet s = new DataSet();a.Fill(s);
this.txtQno.DataBindings.Add("Text", s.Tables[0].DefaultView, "name");no error but no data displayed, could you tell after that what i do to display data in that textBox.
thanks
well nothing really, that is all you need to do, it will automatically bind the data for you showing the value on the Text property (first parameter)
there perhaps is no name value for that field
you may want to, just for testing purposes, databind a datagridview and the datasource together:
this.theDataGridView.DataSource = theDataSet.Tables[0].DefaultView;
and see if there is a value available in the name column.
hi,
as what ahmad said you have to check if there is any data in your table , another way to test tableAdapter.Fill() return int which represent the number of rows that was brought to your table you can expose this number in a message box to check
to move between the records , you can use a bindingsource in between your datasource "your table" and the textbox, it will be something like this
int n = adapter.fill(Mydataset.MyTable);
MessageBox.Show(n);
BindingSource bs = new Bindingsource();
bs.Datasource = Mydataset.MyTable;
txtbx.DataBindings.Add(New System.Windows.Forms.Binding("Text", bs, "name", True));
hope this helps