string sql="select * from w ";
System.Data .OleDb .OleDbDataAdapter da1=new System.Data.OleDb.OleDbDataAdapter (sql,oleDbConnection1)
string insert ="insert into w (name,password) values('"+this.textBox1 .Text  +"','"+this.textBox2 .Text +"')";
               //da1.InsertCommand(insert);

this.Update ();
MessageBox.Show ("添加成功");请教大家,这样的代码要怎样改才可以在数据库中插入一条记录的啊,这个问题困饶我几天了。真的是太感谢大家了的啊!!!

解决方案 »

  1.   

    OleDbConnection conn=new ...;
    conn.open();string insert=...;
    OleDbCommand cmd=new ...;
    cmd.connection=conn;
    cmd.commandtext=insert;
    cmd.executenonquery();conn.close();
      

  2.   

    string conn="....."
    OleDbConnection con=new  OleDbConnection ();
    con.ConnectionString=conn;
    con.open();
    string insert ="insert into w (name,password) values('"+this.textBox1 .Text  +"','"+this.textBox2 .Text +"')";
    OleDbCommand com=new OleDbCommand (insert ,con);
    com.executenonquery();
    conn.close();                
    this.Update ();
    MessageBox.Show ("添加成功");
      

  3.   

    如果你想DataAdapter+DataSet,参看
    http://blog.csdn.net/knight94/archive/2006/03/17/627556.aspx如果直接运行Command,如上就可以了