菜鸟求实例……
学习怎么将datagridview上写数据,然后插入数据库.还有更新,求代码或实例,谢谢

解决方案 »

  1.   

    读取dataGridView中的数据进入到一个数据集DataTable中,然后用SqlDataAdapter的Update可保存和更新到数据库中
      

  2.   

    DataSet ds = new DataSet();
    SqlDataAdapter sda;SqlCommandBuilder scb = new SqlCommandBuilder(sda);
    sda.Update(ds);
    this.dataGridView1.DataSource = ds.Tables[0];
      

  3.   

     SqlConnection con = new SqlConnection("Data Source=PHILEDA1;Initial Catalog=JGD;Integrated Security=True");
                DataSet ds = new DataSet();
                SqlDataAdapter adp = new SqlDataAdapter();
                string sql = "select * from TransactionDate";
                SqlCommand com = new SqlCommand(sql,con);
                SqlCommandBuilder comb = new SqlCommandBuilder(adp);
                adp.InsertCommand = comb.GetInsertCommand();
                adp.UpdateCommand = comb.GetUpdateCommand();
                adp.DeleteCommand = comb.GetDeleteCommand();
                con.Open();
                adp.Update(ds);
                con.Close();我这样写有错么?
    说DataAdapter.SelectCommand 属性需要初始化
      

  4.   

    如何实现DataGridView添加数据到数据库:
    http://topic.csdn.net/u/20100515/20/e78ec082-8c7d-42a0-a5c9-30be285be57e.html
      

  5.   


    SqlConnection con = new SqlConnection("Data Source=PHILEDA1;Initial Catalog=JGD;Integrated Security=True");
                DataSet ds = new DataSet();
                string sql = "select * from TransactionDate";
                SqlCommand com = new SqlCommand(sql,con);
                SqlDataAdapter adp = new SqlDataAdapter(com);
                SqlCommandBuilder comb = new SqlCommandBuilder(adp);
                
                con.Open();
                adp.Update(ds);
                con.Close();