myConnection=new OleDbConnection(GetConString());

myCommand=myConnection.CreateCommand();
myConnection.Open();myCommand.CommandText="Insert into bahDir(bahDir) values  (@bahDira)";
myCommand.Parameters.Add("@bahDira",OleDbType.VarChar);
myCommand.Parameters["@bahDira"].Value="D:\\2006\\02\\27595";
int n=myCommand.ExecuteNonQuery();
执行时却报错怎么回事?

解决方案 »

  1.   

    改成這句試下
    myCommand.Parameters.Add (new OleDbParameter ("@bahDira",OleDbType.VarChar));
      

  2.   

    change
    myCommand.Parameters.Add("@bahDira",OleDbType.VarChar);
    myCommand.Parameters["@bahDira"].Value="D:\\2006\\02\\27595";with
    myCommand.Parameters.Add("@bahDira", "D:\\2006\\02\\27595" );
      

  3.   

    报如下错误:
    未处理的“System.Data.OleDb.OleDbException”类型的异常出现在 system.data.dll 中。
      

  4.   

    是连接的access表,有access操作的例子吗?
      

  5.   

    int n=myCommand.ExecuteNonQuery();
    这句报错!
      

  6.   

    当然有错 这个不是SQL  不能使用@符号的
    你 把 "@" 换成" :" 就可以了 !~
      

  7.   

    myCommand.CommandText="Insert into bahDir (bahDir) values  (?)";
    OLE DB .NET 提供程序不支持将参数传递给 OleDbCommand 调用的 SQL 语句或存储过程的命名参数。在这种情况下,必须使用问号 (?) 占位符。例如:SELECT * FROM Customers WHERE CustomerID = ?因此,向 OleDbParameterCollection 添加 OleDbParameter 对象的顺序必须直接对应于该参数的问号占位符在命令文本中的位置。so you are
      

  8.   

    ADO.NET操作数据
    http://blog.csdn.net/Knight94/archive/2006/04/15/664530.aspx