protected void Page_Load(object sender, EventArgs e) { string connectionString = DBconnectionDemo.LocalLconStr(); SqlConnection cn = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("Select * from Course"); cmd.CommandType = CommandType.Text; cmd.Connection = cn; SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmd); // cn.Open(); DataSet dataSet = new DataSet("myDataSetTableName"); sqlDataAdapter.Fill(dataSet); cmd.Dispose(); sqlDataAdapter.Dispose(); cn.Close(); this.GridView2.DataSource = dataSet; this.GridView2.DataBind(); this.ShowResult.Text = dataSet.GetXml(); }
public static void connectionBuildingDemo() { string connectionString = DBconnectionDemo.LocalLconStr(); SqlConnection cn = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("Select * from course where credits = 3"); cmd.CommandType = CommandType.Text; cmd.Connection = cn; DataSet dataSet = new DataSet( ); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmd); cn.Open(); sqlDataAdapter.Fill(dataSet); cmd.Dispose(); sqlDataAdapter.Dispose(); cn.Close(); }