Return to Snippet

Revision: 43997
at April 27, 2011 19:29 by fengelz


Updated Code
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

var connectionStr = ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.Connection = new SqlConnection(connectionStr);
cmd.Connection.Open();
cmd.CommandText = "SELECT name, lastName FROM myTable";
var users = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(users);
cmd.Connection.Close();
cmd.Connection.Dispose();

Revision: 43996
at April 27, 2011 19:28 by fengelz


Updated Code
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
var connectionStr = ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.Connection = new SqlConnection(connectionStr);
cmd.Connection.Open();
cmd.CommandText = "SELECT name, lastName FROM myTable";
var users = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(users);
cmd.Connection.Close();
cmd.Connection.Dispose();

Revision: 43995
at April 4, 2011 23:25 by fengelz


Initial Code
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
var connectionStr = ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.Connection = new SqlConnection(CONNECTIONSTR);
cmd.Connection.Open();
cmd.CommandText = "SELECT name, lastName FROM myTable";
var users = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(winners);
cmd.Connection.Close();
cmd.Connection.Dispose();

Initial URL

                                

Initial Description
Snip it if you keep forgetting how its done.

Initial Title
Reading data into a dataset in C#

Initial Tags
database, sql, c#

Initial Language
C#