[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

C# SQL Server retrieve data

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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 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