我想复制项表中的特定行,并复制将其复制到新表(name- cart )中。并在 dataGridView 中显示 cart 表中的所有记录。帮助!
con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString = " Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\posdb.mdf;Integrated Security=True";
string query = "INSERT INTO cart (item_id,Description,Unit_Price,Qty) SELECT item_id,Description,price,'" + txtqty.Text + "' FROM items WHERE item_id = '" + textBox1.Text + "'";
string qry = "SELECT * FROM cart";
System.Data.SqlClient.SqlDataAdapter da;
System.Data.SqlClient.SqlDataAdapter da1;
da = new System.Data.SqlClient.SqlDataAdapter(query, con);
da1 = new System.Data.SqlClient.SqlDataAdapter(qry, con);
ds1 = new DataSet();
con.Open();
da1.Fill(ds1,"cart");
con.Close();
dataGridView1.DataSource = ds1;
dataGridView1.DataMember = "cart";
帮助! ......
答案 0 :(得分:2)
protected void btn_Click(object sender, EventArgs e)
{
insert();
View();
}
private void insert()
{
// write insert query
}
private void View()
{
// write select query and bind to grid
}