Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Create DataSet

Posted on 2009-12-21
8
Medium Priority
?
222 Views
Last Modified: 2012-05-08
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.
0
Comment
Question by:chrisryhal
  • 6
  • 2
8 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 26096027
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);

DataSet dSet = new Dataset():
adapter.Fill(dSet);
0
 
LVL 21

Accepted Solution

by:
silemone earned 2000 total points
ID: 26096062
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
 
LVL 21

Expert Comment

by:silemone
ID: 26096071
The namespace -

using System.Data;
using System.Data.SqlClient;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:chrisryhal
ID: 26096105
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
 
LVL 21

Expert Comment

by:silemone
ID: 26096219
oops...type...should be SQLConnection
0
 
LVL 21

Expert Comment

by:silemone
ID: 26096231
excuse typos...
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 26096331
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
 
LVL 21

Expert Comment

by:silemone
ID: 26096679
You're welcome...

cheers.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

571 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