Sql connection
DataTable
• Datatable it is a Collection of Database Rows and Columns
Example : DataTable dt = new DataTable("Student");
Sqlcommand
• In this Scenario Sql Command Acts to point database location and
database query
Connection String and sql query
Example :
string query = "Select * from Table";
• SqlConnection con = new SqlConnection();
• con.ConnectionString = "Data Source=(localdb)MSSQLLocalDB;Initial Catalog=ChartDB;Integrated Security=True";
• SqlCommand cmd = new SqlCommand();
• cmd.CommandText = query;
• cmd.Connection = con;
SqlDataAdapter
• SqlDataAdapter
Finally SqlDataAdapter fetch into Connection & Sqlquery send back to
Datatable
DataSet
• DataSet Which has Currently Strored Single DataBase Table, and Get
Entire Table structure of Rows and colums in a DataBase Table
• DataSet Fetches multiple row at a time
DataTable
• DataTable Which has Currently Strored Single DataBase Table, and Get
Entire Table structure of Rows and colums in a DataBase Table
• Datatable Fetches single row at a time
Example :
DataTable dt = new DataTable("Student");
string query = "Select * from Table";
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=(localdb)MSSQLLocalDB;Initial Catalog=ChartDB;Integrated Security=True";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Open();
da.Fill(dt);
con.Close();
return dt;
THANK YOU

Sql Connection and data table and data set and sample program in C# ....

  • 1.
  • 2.
    DataTable • Datatable itis a Collection of Database Rows and Columns Example : DataTable dt = new DataTable("Student");
  • 3.
    Sqlcommand • In thisScenario Sql Command Acts to point database location and database query Connection String and sql query Example : string query = "Select * from Table"; • SqlConnection con = new SqlConnection(); • con.ConnectionString = "Data Source=(localdb)MSSQLLocalDB;Initial Catalog=ChartDB;Integrated Security=True"; • SqlCommand cmd = new SqlCommand(); • cmd.CommandText = query; • cmd.Connection = con;
  • 4.
    SqlDataAdapter • SqlDataAdapter Finally SqlDataAdapterfetch into Connection & Sqlquery send back to Datatable
  • 5.
    DataSet • DataSet Whichhas Currently Strored Single DataBase Table, and Get Entire Table structure of Rows and colums in a DataBase Table • DataSet Fetches multiple row at a time
  • 6.
    DataTable • DataTable Whichhas Currently Strored Single DataBase Table, and Get Entire Table structure of Rows and colums in a DataBase Table • Datatable Fetches single row at a time
  • 7.
    Example : DataTable dt= new DataTable("Student"); string query = "Select * from Table"; SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=(localdb)MSSQLLocalDB;Initial Catalog=ChartDB;Integrated Security=True"; SqlCommand cmd = new SqlCommand(); cmd.CommandText = query; cmd.Connection = con; SqlDataAdapter da = new SqlDataAdapter(cmd); con.Open(); da.Fill(dt); con.Close(); return dt;
  • 8.

Editor's Notes

  • #8 In this Program we Datatable for Structure Sqlconnection for connect DataBase Table sqlcommand to Data Manipulation in DataBase Table SqlDataAdapter it consists of connection and user query and table fill to DataTable