?
Solved

C# SQL Server retrieve data

Posted on 2014-04-03
3
Medium Priority
?
549 Views
Last Modified: 2014-04-08
I am creating my first C# app. I have to fill a lot of comboboxes and 2 datagridviews. What is the quickest way to fill the controls when using SQL Server.
0
Comment
Question by:Idarac
3 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 1000 total points
ID: 39976310
It depends what your goals are. If it's a quick load for viewing then a SqlDataReader, potentially with multiple result sets, will do the trick. Otherwise hold all your data in a DataSet if you need to hold the data so you can update/write back to the database.

Entity Framework will provide you with a quick drag/drop approach to getting your data loaded.

SqlDataReader sample: http://myvirtualplayground.co.uk/blog/Fundamentals_Reading_From_a_Database_Part_1

Entity Framework resources: http://msdn.microsoft.com/en-US/data/ef
0
 
LVL 16

Accepted Solution

by:
Kalpesh Chhatrala earned 1000 total points
ID: 39981574
you can use like below

using (SqlConnection sqlConn = new SqlConnection("MyConnString"))
{
    SqlCommand sqlCmd = new SqlCommand("SELECT * FROM MyTable", sqlConn);
    sqlConn.Open();
    SqlDataReader sqlR = sqlCmd.ExecuteReader();

    while (sqlR.Read())
    {
        MyCombo.Items.Add(sqlR["name"].ToString());
    }

    sqlR.Close();
}

Open in new window



if you want you can use below C# beginner video tutorial

https://www.youtube.com/playlist?list=PLAC325451207E3105
0
 
LVL 1

Author Closing Comment

by:Idarac
ID: 39986293
Thank you
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

864 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