protected void Button15_Click3(object sender, EventArgs e)
{
string connetionString = null;
SqlConnection connection ;
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
int i = 0;
int j = 0;
connetionString = "Data Source=xxxxx;Initial Catalog=xxxxx;User ID=xxxxx;Password=xxxxxx";
connection = new SqlConnection(connetionString);
try
{
connection.Open();
adapter.SelectCommand = new SqlCommand("insert into Table2(Code, Model, Num, Qty) select Code, Model, Num, Qty from Table1", connection);
adapter.Fill(ds);
connection.Close();
String str2 = "select * from Table2;";
SqlCommand xp2 = new SqlCommand(str2, con);
con.Open();
SqlDataAdapter da2 = new SqlDataAdapter();
da2.SelectCommand = xp2;
DataSet ds2 = new DataSet();
da2.Fill(ds2, "Table2");
con.Close();
for (i = 0; i <= Convert.ToInt32(ds2.Tables[0].Rows[i]["Qty"].ToString()) ; i++)
{
String str1 = "insert into Table2(Code, Model, Num, Qty) select Code, Model, Num, Qty from Table1;";
SqlCommand xp1 = new SqlCommand(str1, con);
con.Open();
SqlDataAdapter da1 = new SqlDataAdapter();
da1.SelectCommand = xp1;
DataSet ds1 = new DataSet();
da1.Fill(ds1, "Code");
GridView1.DataSource = ds1;
con.Close();
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}