dtDataAdapter.UpdateCommand.Parameters.Add(new Parameter("@spsl", SqlDbType.Float, 8, "spsl"))
        Dim workParm As SqlParameter = new Parameter("@chdm", SqlDbType.Char)
        workParm.SourceColumn = "chdm"
        workParm.SourceVersion = DataRowVersion.Original
dtDataAdapter.UpdateCommand.Parameters.Add(workParm );

解决方案 »

  1.   

    谢谢楼上的,不过不好用。加上就提示我:
    此 SqlParameterCollection 已包含带有ParameterName“@chdm”的 SqlParameter。
      

  2.   

    郁闷!
    看不懂那代码,参考我的C#吧string sqlstr="SELECT * FROM news where news_id='新闻ID号";
    SqlConnection myconn=new SqlConnection("连接字符串");
    try
    {
    myAdapter=new SqlDataAdapter(sqlstr,myconn);
    theBuilder=new SqlCommandBuilder(myAdapter); upds=new DataSet();
    myAdapter.Fill(upds,"news"); DataRow theRow=this.upds.Tables["news"].Rows[0];

    }
    catch(Exception er)
    {
    MessageBox.Show(er.ToString(),"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
    }
    finally
    {
    myconn.Close();
    }===========================================================================try
    {
    DataRow theRow=this.upds.Tables["news_title"].Rows[0]; theRow["news_title"]=tb_title.Text;

    myAdapter.Update(upds,"news_title");
    MessageBox.Show("修改成功!","信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
    this.Close();
    }
    catch(Exception er)
    {
    MessageBox.Show(er.ToString(),"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
    }==========================================
    上面凡是没有定义的变量都是全局变量
      

  3.   

    public DataSet RunProcDS(string procName, SqlParameter[] prams) {
    SqlCommand cmd = CreateCommand(procName, prams);
    SqlDataAdapter ada =new SqlDataAdapter(cmd);
    DataSet ds=new DataSet();
    ada.Fill(ds,"t1");
    return ds;
    }
    private SqlCommand CreateCommand(string procName, SqlParameter[] prams) {
    // make sure connection is open
    Open(); //command = new SqlCommand( sprocName, new SqlConnection( ConfigManager.DALConnectionString ) );
    SqlCommand cmd = new SqlCommand(procName, con);
    cmd.CommandType = CommandType.StoredProcedure; // add proc parameters
    if (prams != null) {
    foreach (SqlParameter parameter in prams)
    cmd.Parameters.Add(parameter);
    }

      // return param
    cmd.Parameters.Add(
    new SqlParameter("ReturnValue", SqlDbType.Int, 4,
    ParameterDirection.ReturnValue, false, 0, 0,
    string.Empty, DataRowVersion.Default, null)); return cmd;
    }
      

  4.   

    Dim myConnection As New SqlConnection(Session("strConnection"))  '连接数据库
            Dim dtDataAdapter As New SqlDataAdapter("select * from erp_sb_cgjhcb where cgjhdh='" & Me.Label1.Text & "'", myConnection)        dtDataAdapter.UpdateCommand = New SqlCommand("Update erp_sb_cgjhcb set spsl=@spsl where cgjhdh='" & Me.Label1.Text & "' and chdm=@chdm", myConnection)
            dtDataAdapter.UpdateCommand.Parameters.Add("@spsl", SqlDbType.Float, 8, "spsl")        Dim workParm As SqlParameter = dtDataAdapter.UpdateCommand.Parameters.Add("@chdm", SqlDbType.Char)
            workParm.SourceColumn = "chdm"
            workParm.SourceVersion = DataRowVersion.Original        Dim Row As DataRow = ds.Tables("Table").Rows(0)
            Row = ds.Tables("Table").NewRow
            Row("spsl") = 800        dtDataAdapter.Update(ds)结果提示我:
    Prepared statement '(@spsl float,@chdm char(10))Update erp_sb_cgjhcb set spsl=@spsl ' expects parameter @spsl, which was not supplied.
      

  5.   

    用sql语句更新吧,没那么多的麻烦呀!