Binding SqlCE to Datagrid

  • Thread starter Thread starter Nathan Zumwalt
  • Start date Start date
N

Nathan Zumwalt

I've created an SqlCE database and I'm trying to bind it to a DataGrid
using C#.

I tried to use this code:
http://samples.gotdotnet.com/quickstart/CompactFramework/doc/datagrid.aspx

After converting it to C#, I get the following error:
'System.Data.SqlServerCe.SqlCeDataAdapter' does not contain a
definition for 'Fill'.

Am I making some newbie mistake? If this isn't the way to do it, how
do I bind my SqlCE connection to a Datagrid?

-Nathan
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top