日期:2014-05-18 浏览次数:20822 次
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex==4) { string str = "server=localhost;database=ts_sell;uid=sa;pwd="; string cid = "DD" + DateTime.Now.ToString("yyyyMMddhhmm"); SqlConnection scon = new SqlConnection(str); scon.Open(); string sql = "insert into t_dingdan values ('" +cid + "','" + dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() + "','" + dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() + "','" + dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString() + "','" + dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString() + "','" + user + "')"; SqlCommand scom = new SqlCommand(sql, scon); scom.ExecuteNonQuery(); MessageBox.Show("保存成功"); scon.Close(); } }