Create DataSet

Can someone please provide a snippet / example on how to create a dataset to be able to make use of within an application within C# with a  simple SELECT statement to a SQL DB?  

It needs to be programmibly without any of the wizards unfortuantly because its for a code behind that is built into an already compiled program (ERP System) that allows me to supply custom code.
LVL 2
chrisryhalAsked:
Who is Participating?
 
silemoneCommented:
more complete...

string connStr = "place connectionstring here";
string query = "Select Statement here";
SqlConnection conn = null;
SqlCommand cmd = null;
SqlDataAdapter adapter = null;

try{
conn= new Connection (connStr);
conn.Open();
cmd = new SqlCommand(query, conn);
adapter = new SqlDataAdapter(cmd);

DataSet dSet = new Dataset():
adapter.Fill(dSet);
}
catch(Exception e)
{
   //some error message
}
finally
{
     conn.Close():
}
0
 
silemoneCommented:
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);

DataSet dSet = new Dataset():
adapter.Fill(dSet);
0
 
silemoneCommented:
The namespace -

using System.Data;
using System.Data.SqlClient;
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
chrisryhalAuthor Commented:
The type or namespace name 'Connection' could not be found (are you missing a using directive or an assembly reference?)

I supplied both namespaces.  This is the only error, though you had a few typos, but no biggy :)
0
 
silemoneCommented:
oops...type...should be SQLConnection
0
 
silemoneCommented:
excuse typos...
0
 
chrisryhalAuthor Commented:
silemone,

Not a problem about the typo's (GRIN).  I'm the worst myself at my grammer, etc.

I actually thought that might have been the issue, but I'm VERY green to C#.  I can tear pretty much through VB.NET and with my VB.NET skills have had pretty good success at most things with C#, its just getting over the explicitcy that C# has versus VB obviously.

That worked, I appreciate all your help!!!!!

0
 
silemoneCommented:
You're welcome...

cheers.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.