Solved

Can I use ADO and disconnected recordsets in C#

Posted on 2008-10-27
7
548 Views
Last Modified: 2012-05-05
I am a big fan of ADO recordsets in the old VB6 world.  I load them with data, save them as files and then reload them.  They are a wonderful say of saving settings.  I also iterate through them to load data into grids to display to the user.  I am not a big fan of having a grid bound to the database.

So - can I do this in C#?  I am writing my first C# doofer that has a UI ( all the others I did were very simple web services).  

Thanks in advance.

Todd
0
Comment
Question by:toddism
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Expert Comment

by:Blackninja2007
ID: 22812331
ADO.NET can work disconnected ... indeed it does alot disconnected.
0
 
LVL 3

Expert Comment

by:Blackninja2007
ID: 22812339
.... just create a  Dataset ... then close the connection.
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 22812376
To save to and load from a file, use Dataset.WriteXml() and Dataset.ReadXml()

Dataset is really a lot more powerful than recordset, once you get to know it.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:toddism
ID: 22812414
jcoehoorn: can I create datasets dynamically?  append fields, etc then iterate through it?  
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 22812535
Sure.

DatasSt ds = new DataSet();

DataTable dt = ds.Tables.Add();
 

dt.Columns.Add("MyColumn1");

dt.Columns.Add("MyColumn2");
 

dt.Rows.Add(new object[] {"value1","value2"});

dt.Rows.Add(new object[] {"value3", value4"});
 

foreach (DataRow row in dt.Rows)

{

    Console.WriteLine("New Row:");

    foreach (DataColumn col in dt.Columns)

    {

        Console.WriteLine("\t" + col.ColumnName + ": " + row[col].ToString());

    }

}

Open in new window

0
 
LVL 18

Accepted Solution

by:
jcoehoorn earned 250 total points
ID: 22812541
Oops: missed a double quotes in that snippet.

DatasSt ds = new DataSet();

DataTable dt = ds.Tables.Add();

 

dt.Columns.Add("MyColumn1");

dt.Columns.Add("MyColumn2");

 

dt.Rows.Add(new object[] {"value1","value2"});

dt.Rows.Add(new object[] {"value3", "value4"});

 

foreach (DataRow row in dt.Rows)

{

    Console.WriteLine("New Row:");

    foreach (DataColumn col in dt.Columns)

    {

        Console.WriteLine("\t" + col.ColumnName + ": " + row[col].ToString());

    }

}

Open in new window

0
 

Author Closing Comment

by:toddism
ID: 31510281
Excellent answer.  Exactly what I was looking for.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 160
ConsoleSql 1 34
which object should i use (efficiency) 5 46
Linq Help 1 35
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now