?
Solved

C# SQL Server retrieve data

Posted on 2014-04-03
3
Medium Priority
?
545 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 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

777 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