对了第二个问题它指的错误是这行 myCmd.ExecuteNonQuery();

解决方案 »

  1.   

    insert的代码:
    OleDbConnection myConn = new OleDbConnection(@"Integrated Security=SSPI;Packet Size=4096;Data Source=FAN;Tag with column collation when possible=False;Initial Catalog=Market;Use Procedure for Prepare=1;Auto Translate=True;Persist Security Info=False;Provider=""SQLOLEDB.1"";Workstation ID=FAN;Use Encryption for Data=False");
    myConn.Open();
    string strInsert = " INSERT INTO Orderz( orderid,goodsname,customerid,quantity,ordersum,orderdate ) VALUES('"
    + txtOI.Text +"','"
    + txtGS.Text +"','"
    + txtCI.Text +"','"
    + txtQ.Text +"','"+txtOS.Text+"','"+txtOD.Text+"')";
    //MessageBox.Show(strInsert);
    OleDbCommand myCmd = new OleDbCommand(strInsert,myConn);
    myCmd.ExecuteNonQuery();
    myConn.Close();
    MessageBox.Show("成功添加图书" + txtOI.Text + "的信息,请点击‘重新加载数据’以显示信息!","图书管理系统",MessageBoxButtons.OK,MessageBoxIcon.Information );
      

  2.   

    update的代码:
    //信息合法性检查
    if (textBox7.Text=="" || txtCI.Text =="" || txtGS.Text=="" || txtOS.Text=="" || txtQ.Text=="")
    {
    MessageBox.Show("提交的信息不完全!","图书管理系统",MessageBoxButtons.OK,MessageBoxIcon.Information );
    return;
    }
    try
    {
    //this.dataGrid1.EndInit();
    this.mybind.EndCurrentEdit();
    this.ccDA.Update(this.ccDS,"Orderz");
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
      

  3.   

    帖个我的代码看看吧。
    public string FillMainDS_OLEDB(string Connection,string Command,string TableName) 
    {
    //自定义函数
    //功能:采用OLEDB方式连接,将Command命令通过Connection查询出结果,填充到MainDataSet中的TableName表中
    //输入:Connection数据连接串,Command SQL命令,TableName MainDataSet中的表名
    //输出:直接修改MainDataSet。
    //返回:提示信息。
    try
    {
    OleDbConnection conn = new OleDbConnection(Connection);
    conn.Open();
    OleDbCommand comm = new OleDbCommand(Command,conn);
    OleDbDataAdapter adapter = new OleDbDataAdapter(comm);
    adapter.Fill(MainDataSet,TableName);
    conn.Close();
    return "成功。";
    }
    catch(Exception e3)
    {
    return "失败。"+ e3.ToString ( );
    }
    }

    public string FillMainDS_SQL (string Connection,string Command,string TableName) 

    //自定义函数
    //功能:采用SQL Client方式连接,将Command命令通过Connection查询出结果,填充到MainDataSet中的TableName表中
    //输入:Connection数据连接串,Command SQL命令,TableName MainDataSet中的表名
    //输出:直接修改MainDataSet。
    //返回:提示信息。
    try 

    SqlConnection myConn = new SqlConnection ( Connection ) ; 
    myConn.Open ( ) ; 
    SqlDataAdapter myAdapter = new SqlDataAdapter ( Command , myConn ) ; 
    myAdapter.Fill (MainDataSet,TableName) ; 
    myConn.Close ( ) ; 
    return "成功。";

    catch ( Exception e4) 

    return "失败。"+ e4.ToString ( );


    public string ExeSQL_OLEDB(string Connection,string Command)
    {
    //自定义函数
    //功能:执行SQL命令,通过Oledb连接
    //输入:Connection数据连接串,Command SQL命令
    //输出:直接修改数据库
    //返回:提示信息。
    try
    {
    OleDbConnection conn = new OleDbConnection(Connection);
    conn.Open();
    OleDbCommand comm = new OleDbCommand(Command,conn);
    comm.ExecuteNonQuery();
    conn.Close();
    return "成功。";
    }
    catch(Exception e6){return "失败。"+e6.ToString();}
    }
    public string ExeSQL_SQL(string Connection,string Command)
    {
    //自定义函数
    //功能:执行SQL命令,通过SQL Client连接
    //输入:Connection数据连接串,Command SQL命令
    //输出:直接修改数据库
    //返回:提示信息。
    try
    {
    SqlConnection myConn = new SqlConnection ( Connection ) ; 
    myConn.Open ( ) ; 
    SqlCommand myCom=new SqlCommand(Command,myConn);
    myCom.ExecuteNonQuery ( ) ;
    myConn.Close ( ) ;
    return "成功。";
    }
    catch(Exception e7){return "失败。"+e7.ToString();}
    }
      

  4.   

    connection连接串的示例:
    sql连接方式
    data source=;initial catalog=;password=;persist security info=True;user id=;workstation id=;packet size=OLEDB连接方式
    informix的
    Provider=Ifxoledbc.2;password=;User ID=;Data Source=@;Persist Security Info=true
      

  5.   

    一定要改你的代码么?
    1、你的数据库联接写的太负杂了,没那么恐怖;
    2、insert的时候不是出错么,你用try...catch把错误抓出来;
    3、按下update出现  未将对象引用设置到对象实例.(查查有没有什么对象没有new)