日期:2014-05-20  浏览次数:20462 次

求助!DataGrid更新数据时报错
OleDbDataAdapter   myAdapter;
OleDbConnection   myConnection;
OleDbParameter   myParamSup;
string   SchemaName   =   "ZLIB ";
myConnection   =   new   OleDbConnection(Session[ "ConnStr "].ToString());
myAdapter   =   new   OleDbDataAdapter( "SELECT   vcsupid,vclot,vcitem,nnum,vcresc,vcren,vctime     FROM   "   +   SchemaName   +   ".bcmx   WHERE   vcsupid   =   ?   ",   myConnection);
myParamSup   =   myAdapter.SelectCommand.Parameters.Add(new   OleDbParameter( "vcsupid ",   OleDbType.VarChar));
myParamSup.Precision   =   30;
myParamSup.Scale   =   0;
OleDbCommandBuilder   myBuilder   =   new   OleDbCommandBuilder(myAdapter);  
myAdapter.SelectCommand.Parameters[ "vcsupid "].Value   =   "10118 ";
DataTable   myDataTable   =   new   DataTable();
DataRow   myDataRow;
myDataTable.Clear();
myAdapter.Fill(myDataTable);
DropDownList   supList;
TextBox   numText;
foreach   (DataGridItem   dgi   in   arDataGrid.Items)
{
myDataRow   =   myDataTable.NewRow();
myDataRow[ "vcsupid "]   =   "10118 ";
myDataRow[ "vclot "]   =   dgi.Cells[2].Text.Trim();  
myDataRow[ "vcitem "]   =   dgi.Cells[3].Text.Trim();
myDataRow[ "nnum "]   =   Convert.ToDecimal(numText.Text.Trim());
myDataRow[ "vcresc "]   =   supList.SelectedItem.Value.ToString().Trim()
myDataTable.Rows.Add(myDataRow);
}
try
{
myAdapter.Update(myDataTable);
}
catch   (OleDbException   odeInfo)
{
  hasError   =   true;
  MsgBar.Visible   =   true;
  MsgBar.InnerHtml   +=   "错误: "   +   odeInfo.ErrorCode.ToString()   +   ":   "   +   odeInfo.Message;
  }

试运行   执行到myAdapter.Update(myDataTable);时   报错:
OleDbCommand.Prepare   方法要求所有可变长度参数具有显式设置的非零“大小”

请教大家,急用   谢谢!

------解决方案--------------------
C#看得很困难,只有帮顶了
------解决方案--------------------
关注
------解决方案--------------------
应该是数据类型和数据库不匹配 检查一下
------解决方案--------------------
myParamSup = myAdapter.SelectCommand.Parameters.Add(new OleDbParameter( "vcsupid ", OleDbType.VarChar));
改为:

myParamSup = myAdapter.SelectCommand.Parameters.Add(new OleDbParameter( "vcsupid ", OleDbType.VarChar,100)); //指定下长度试试

------解决方案--------------------
同意楼上的,须指定大小
------解决方案--------------------
TO:myParamSup = myAdapter.SelectCommand.Parameters.Add(new OleDbParameter( "vcsupid ", OleDbType.VarChar));
myAdapter.SelectCommand.Parameters[ "vcsupid "].Value = "10118 ";

指定参数长度即可...

或者改成如下形式:
myAdapter.SelectCommand.Parameters.AddWithValue( "@vcsupid ", "100118 ");