slip Posted January 16, 2006 Posted January 16, 2006 Im using C# 2003 and right now im reading and writing directly to the database, but I belive at some point soon I will need to use datasets, I have never used datasets before so I have a few questions about them. 1. how easy will it be to convert my current update/read functions, or am I going to have to recode it all? 2. When using datasets 1 dataset will hold all my tables right or do I need to create a dataset for each table? also if anyone knows of a good sample of doing this a link would be great cheers :D Quote
Mister E Posted January 18, 2006 Posted January 18, 2006 1. Since you are connecting to Access, I assume you already have an OleDbCommand. If this is the case then you only need to create an OleDbDataAdapter instance. From there you can fill a DataSet instance: using System; using System.Data; using System.Data.OleDb; // ... OleDbConnection conn = new OleDbConnection("YOUR CONNECTION STRING"); conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.CommandText = "SELECT * FROM People"; cmd.CommandType = CommandType.Text; cmd.Connection = conn; OleDbDataAdapter da = new OleDbDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); conn.Close(); foreach (DataTable dt in ds.Tables) { Console.WriteLine("TABLE: " + dt.TableName); foreach (DataRow dr in dt.Rows) { // access field with dr["FieldName"] } } 2. Each DataSet has a collection of DataTables. See the above example. Quote
slip Posted January 19, 2006 Author Posted January 19, 2006 Now when I load in all my tables can I just use this for each new table cmd = new OleDbCmmand() and do updates to datasets work the same way as directly to the database, and can I use my current commands to check the dataset? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.