Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQLDataAdapter on WinForm and strongly typed data set for store procedures

Posted on 2012-03-22
3
Medium Priority
?
368 Views
Last Modified: 2012-03-23
I am looking for a simple example of using the SqlDataAdapter control on a winform to read a stored procedure as a strongly typed dataset.
There are countless examples of creating your own control in code and then accessing it with a loosely typed set.

Can you point me towards a simple example?
 sqlConnection1.Open();
            sqlDataAdapter1.SelectCommand.BeginExecuteReader();
            DataTable da = new DataTable();
            sqlDataAdapter1.Fill(da);
            foreach (DataRow oneRow in da.Rows)
            {
               
            }

This code does not work because it is not Asychronous.
0
Comment
Question by:wilfordrocks
3 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 2000 total points
ID: 37752598
Read this article from msdn, step by step resolution to your problem:-
http://support.microsoft.com/kb/320714
         SqlConnection cn = new                                            
SqlConnection("server=localhost;uid=sa;pwd=abcd;database=northwind");
	SqlCommand cmd = new SqlCommand("select * from [Alphabetical list of products]", cn);
	SqlDataAdapter da = new SqlDataAdapter(cmd);
	dsProducts tds = new dsProducts();

	da.Fill(tds, tds.Tables[0].TableName);

Open in new window

0
 
LVL 5

Expert Comment

by:Aruiz04
ID: 37752621
        SqlConnection cn = new SqlConnection();
        SqlCommand cmd = new SqlCommand("StoreProcedureName", cn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable("TableNameFromYourTypedDataset");
        da.Fill(dt);
        foreach (DataRow dr in dt.Rows)
        {
            //Process here
        }

Open in new window

0
 

Author Closing Comment

by:wilfordrocks
ID: 37758859
thanks for the link
0

Featured Post

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!

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses

877 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