I created with Visual Studio 2010 Express a Sql Compact Database (sdf-File), with several tables and relations. From this database I generated a strongly typed dataset.
Now I want to fill the dataset with the content from the database.
So I used following code to connect to the database and fill the dataset.
//My strongly typed dataset
localData = new LokalStorageDataSet();
//SqlCe-Connection
localConnection = new SqlCeConnection(@"Data Source=|DataDirectory|\TempStorage.sdf; Password='xyc';Persist Security Info=True");
localConnection.Open();
SqlCeCommand command = new SqlCeCommand("SELECT * FROM progstates", localConnection);
localDataAdapter = new SqlCeDataAdapter(command);
localDataAdapter.Fill(localData);
The problem is that no rows were added to my dataset, although in the database there are rows.
If I use a SqlCeReader to read the results of the SqlCeCommand, the reader return the rows:
SqlCeDataReader dr = command.ExecuteReader();
while (dr.Read())
{
...
}
Can you give me the reason why my dataset don’t get the rows from the table in the dataset?
EDIT: I saw that in my dataset a new datatable were created named ‘Table’ with the same columns like the one I requested (progstate) but also this datatable has a rowCount of 0.
Or You cant do this with DataAdapter like this :-