I want to copy particular row in items table and copy it into a new table (name- cart). And display the all records in cart table in a dataGridView. Help !
我想复制items表中的特定行并将其复制到新表(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";
Help ! ......
帮帮我 ! ......
1 个解决方案
#1
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
}
#1
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
}