Solved

C# SQL Server retrieve data

Posted on 2014-04-03
3
541 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 250 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 250 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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