Solved

C# SQL Server retrieve data

Posted on 2014-04-03
3
524 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 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now