protected void Page_Load(object sender, EventArgs e)
{
try
{
// Declare new Dataset object
DataSet dataset = new DataSet();
// Declare new SQL Command object
SqlCommand cmd = new SqlCommand("select Product.prdId, Product.prdName, Table1.weight from Product inner join Table1 ON Product.prdId = Table1.ProductId");
cmd.CommandType = CommandType.Text;
// Declare SQL Data Adapter object
SqlDataAdapter dataAdapter;
// Declare new SQL Connection object
SqlConnection reportConnection = new SqlConnection( "Data Source=.\\sqlexpress;Initial Catalog=master;Integrated Security=True");
cmd.Connection = reportConnection;
//reportConnection = cmd.Connection;
// Open database Connection
reportConnection.Open();
// Initialize the data adapter object with command object
dataAdapter = new SqlDataAdapter(cmd);
dataAdapter.SelectCommand = cmd;
// Fill the dataset
dataAdapter.Fill(dataset);
testGrid.DataSource= dataset.Tables[0];
testGrid.DataBind();
}
catch (Exception ex)
{
throw ex;
}
{
try
{
// Declare new Dataset object
DataSet dataset = new DataSet();
// Declare new SQL Command object
SqlCommand cmd = new SqlCommand("select Product.prdId, Product.prdName, Table1.weight from Product inner join Table1 ON Product.prdId = Table1.ProductId");
cmd.CommandType = CommandType.Text;
// Declare SQL Data Adapter object
SqlDataAdapter dataAdapter;
// Declare new SQL Connection object
SqlConnection reportConnection = new SqlConnection( "Data Source=.\\sqlexpress;Initial Catalog=master;Integrated Security=True");
cmd.Connection = reportConnection;
//reportConnection = cmd.Connection;
// Open database Connection
reportConnection.Open();
// Initialize the data adapter object with command object
dataAdapter = new SqlDataAdapter(cmd);
dataAdapter.SelectCommand = cmd;
// Fill the dataset
dataAdapter.Fill(dataset);
testGrid.DataSource= dataset.Tables[0];
testGrid.DataBind();
}
catch (Exception ex)
{
throw ex;
}
No comments:
Post a Comment