Click to See Complete Forum and Search --> : Searching operation in datatable


Lovely301
February 16th, 2008, 03:15 AM
Hi all,

I want to search a particular row from a datatable and display it on a datagrid.Am using sql queries to insert, update and in the same way am using select query to do search operation. The statements i have written are like this(am using cldb dll)

private void Search_Click(object sender, System.EventArgs e)
{
ds = clDb.oDb.executeDataSet("Mydatabase","SELECT * FROM Books WHERE '"+listBox1.SelectedItem.ToString()+"' = '"+searchtxtbx.Text+"'");
dataGrid1.DataSource = ds;
dataGrid1.DataMember = ds.Tables[0].ToString();
}
when i click on the serach button, it is displaying nothing on the datagrid. can anyone pls tel me where i have done the mistake.

Thanks in advance

nelo
February 17th, 2008, 04:28 PM
dataGrid1.DataMember = ds.Tables[0].ToString();


I think the DataMember should reference a field/column in your database table and not the table name which is what you're doing. It's not clear what development environment you're using but I would suggest using the designer to set up such properties including the actual datasource. You can read about Object data sources in MSDN.