ASP.NET: Get SQL data from in ASP.NET C#

Direct Data Access

public void PopulateData()

{

SqlConnection conn = new SqlConnection();

conn.ConnectionString =

ConfigurationManager.ConnectionStrings[“simpletopupConnectionString”].ConnectionString.ToString();

 

SqlCommand command = new SqlCommand(“SELECT * from

tOrder;”, conn);

command.Connection.Open();

 

SqlDataReader reader = command.ExecuteReader();

DataTable table = new DataTable();

table.Load(reader);

 

command.Connection.Close();

 

GridView1.DataSource = table;

GridView1.DataBind();

}

public void CreateCommand()

{

SqlCommand command = new SqlCommand();

command.CommandText = “SELECT * FROM Categories ORDER

BY CategoryID”;

command.CommandTimeout = 15;

command.CommandType = CommandType.Text;

}

public void PopulateData()

{

SqlConnection conn = new SqlConnection();

conn.ConnectionString =

ConfigurationManager.ConnectionStrings[“simpletopupConnectionString”].ConnectionString.ToString();

 

SqlCommand command = new SqlCommand();

command.CommandText = “SELECT * from tOrder;”;

command.CommandType = CommandType.Text;

command.Connection = conn;

command.Connection.Open();

 

SqlDataReader reader = command.ExecuteReader();

DataTable table = new DataTable();

table.Load(reader);

 

command.Connection.Close();

 

GridView1.DataSource = table;

GridView1.DataBind();

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s