C#一个困扰我几十天的小问题!!!
方法一:
OleDbConnection cnn = new OleDbConnection( "Provider=vfpoledb.1;Data Source=D:\\mydata.dbc;Collating Sequence=machine; ");
cnn.Open();
OleDbCommand cmd = new OleDbCommand( "update mydbf set photo=@zp where id= '0001 ' ", cnn);
cmd.Parameters.Add( "@zp ", OleDbType.VarBinary);
cmd.Parameters[ "@name "].Value = buff; //buff为本人存放照片的byte[]变量
cmd.ExecuteNonQuery();
出现“Syntax error”错误。
方法二:
OdbcConnection cnn = new OdbcConnection( "Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDB=D:\\mydata.dbc;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO; ");
cnn.Open();
OdbcCommand cmd = new OdbcCommand( "update mydbf set photo=@zp where id= '0001 ' ", cnn);
cmd.Parameters.Add( "@zp ", OleDbType.VarBinary);
cmd.Parameters[ "@zp "].Value = buff;
cmd.ExecuteNonQuery();
出现“ERROR [42000] [Microsoft][ODBC Visual FoxPro Driver]Syntax error.”错误。
VFP表就不支持带参数的update命令?有解决办法吗?替代办法也行啊!!!
------解决方案--------------------把@zp换成 ? 试试
OdbcConnection cnn = new OdbcConnection( "Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDB=D:\\mydata.dbc;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO; ");
cnn.Open();
OdbcCommand cmd = new OdbcCommand( "update mydbf set photo=? where id= '0001 ' ", cnn);
cmd.Parameters.Add( "? ", OleDbType.VarBinary).Value = buff;
cmd.ExecuteNonQuery();