日期:2014-05-18 浏览次数:21234 次
//数据库操作 public int SqlUpdate(string sql) { try { //conn数据库连接自己定义 cmd = new SqlCommand(sql,conn); conn.Open(); int line = cmd.ExecuteNonQuery(); conn.Close(); return line; } catch (Exception ex) { throw ex; } } //datagridview会有一空行,所以-1 for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { //定义j,想取第几列自己设置 int j = 0; string a= dataGridView1.Rows[i].Cells[j + 1].Value.ToString(); string b= dataGridView1.Rows[i].Cells[j + 2].Value.ToString(); string b= dataGridView1.Rows[i].Cells[j + 3].Value.ToString(); string d= dataGridView1.Rows[i].Cells[j + 4].Value.ToString(); string sql = @"insert into 表名('单据编号','货料编号','数量','单价','存入表'); values('" + a+ "','" + b+ "','" + c+ "','" + d+ "' )"; //调用方法 SqlUpdate(sql); }