ADO.NET - Working with DataSet

S

Sheikko

ADO.NET - Working with DataSet
=========================

HI, I want to create an application that interact with a DB. I wont to
use SQL statement, but I want to use DataSet.
- I have created my application
- From SERVER EXPLORER panel, I have added a connection to a database
(MyDB) and the name of the dataset is "MyDBDataSet" .
- From DATA SOURCE panel, I have added Tables that I want to use
(Setting).
- When I click a button from my application I want to populate a table
with some values, so I write the following code:

MyDBDataSet.SettingDataTable Setting = new
MyDBDataSet.SettingDataTable();
DataRow SettingRow = Setting.NewRow();

private void button1_Click(object sender, EventArgs e)
{
SettingRow["Name"] = "Name1";
SettingRow["Age"] = 26;
SettingRow["City"] = "City1";

Setting.Rows.Add(SettingRow);
Setting.AcceptChanges();
}

When I close the application the Database is not Syncronized with the
DataTable.
Have you any Idea?
I want to make it working with Pocket PC, but I have the same problem
on the PC.
I found some examples in the net, and they make the same operations I
made.

Here some links:
http://www.java2s.com/Code/CSharp/D...objectandsynchronizingthosechangeswiththe.htm
http://www.functionx.com/vcsharp/databases/datarow.htm
http://en.csharp-online.net/Working_with_Data—Adding_Rows_of_Data

THank you very much
 
J

Jeff Hopper

Instead of your current approach, if you really want to use a DataSet, I
would recommend using a DataAdapter to fill it. See the following MSDN help
for starters: http://msdn2.microsoft.com/en-us/library/377a8x4t(VS.80).aspx.

You might also want to consider using a DataReader if a forward-only,
read-only view of your data meets your needs. It uses less resources and can
be faster than a DataSet. Here is an explanation/example:
http://msdn2.microsoft.com/en-us/library/haa3afyz(vs.80).aspx.

Special SQL Server CE versions of the objects are available in Windows
Mobile apps:
SQLCEDataReader: http://support.microsoft.com/kb/325815
SQLCEDataAdapter:
http://msdn2.microsoft.com/en-us/library/system.data.sqlserverce.sqlcedataadapter(VS.80).aspx

Also, for SQL Server 2005 Compact Edition, you have a 3rd option: the
SqlCeResultSet class. It's lighter weight (performs better) than the
adapter, but is still updateable and scrollable, unlike the reader.
 
S

Sheikko

Instead of your current approach, if you really want to use a DataSet, I
would recommend using a DataAdapter to fill it. See the following MSDN help
for starters:http://msdn2.microsoft.com/en-us/library/377a8x4t(VS.80).aspx.

You might also want to consider using a DataReader if a forward-only,
read-only view of your data meets your needs. It uses less resources and can
be faster than a DataSet. Here is an explanation/example:http://msdn2.microsoft.com/en-us/library/haa3afyz(vs.80).aspx.

Special SQL Server CE versions of the objects are available in Windows
Mobile apps:
SQLCEDataReader:http://support.microsoft.com/kb/325815
SQLCEDataAdapter:http://msdn2.microsoft.com/en-us/library/system.data.sqlserverce.sqlc...

Also, for SQL Server 2005 Compact Edition, you have a 3rd option: the
SqlCeResultSet class. It's lighter weight (performs better) than the
adapter, but is still updateable and scrollable, unlike the reader.


ADO.NET - Working with DataSet
=========================
HI, I want to create an application that interact with a DB. I wont to
use SQL statement, but I want to use DataSet.
- I have created my application
- From SERVER EXPLORER panel, I have added a connection to a database
(MyDB) and the name of the dataset is "MyDBDataSet" .
- From DATA SOURCE panel, I have added Tables that I want to use
(Setting).
- When I click a button from my application I want to populate a table
with some values, so I write the following code:
MyDBDataSet.SettingDataTable Setting = new
MyDBDataSet.SettingDataTable();
DataRow SettingRow = Setting.NewRow();
private void button1_Click(object sender, EventArgs e)
{
SettingRow["Name"] = "Name1";
SettingRow["Age"] = 26;
SettingRow["City"] = "City1";
Setting.Rows.Add(SettingRow);
Setting.AcceptChanges();
}

When I close the application the Database is not Syncronized with the
DataTable.
Have you any Idea?
I want to make it working with Pocket PC, but I have the same problem
on the PC.
I found some examples in the net, and they make the same operations I
made.
THank you very much

THank you very much. I have solved problem using the Table Adapter,
and I have learned also to use TableAdapter methods like insert,
update, getdata and also to create other methods to use with it.

thank you very much
 

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

Top