Binding SqlCE to Datagrid

  • Thread starter Thread starter Nathan Zumwalt
  • Start date Start date
You don't really bind a connection to a grid. You bind a table to a grid.
Something like:

String query = String.Format( "SELECT * FROM {0};", UpdateSelectEdit.Text );

SqlCommand cmd = new SqlCommand( query,

sqlconnect );

dataset = new DataSet();

dataadapter = new SqlDataAdapter();

dataadapter.SelectCommand = cmd;

dataadapter.Fill(dataset);

ResultGrid.DataSource = dataset.Tables[ 0 ];

In this case, UpdateSelectEdit is a TextEdit where the table name is entered
by the user. Sqlconnect is the SQL connection object.



Paul T.
 
Also ensure that you have set Reference to System.Data.Common under project
references.

Best Regards,
Y. Sivaram
 
This was my problem.... I didn't have a reference to the
System.Data.Common namespace.

Thanks!

-Nathan
 
Back
Top