开发者

Working with Sybase and a DataAdapter

I'm writing a small Windows form application in .NET 2.0.

I have an OdbcDataAdapter has the Insert and Update statements specified like so. The select statement is also defined earlier in this code.

OdbcCommand insertCommand = _connection.CreateCommand();
insertCommand.CommandText = "INSERT INTO myTable (ReportID) VALUES (?ReportId)";
_dataAdapter.InsertCommand = insertCommand;
_dataAdapter.InsertCommand.Parameters.Add(new OdbcParameter { ParameterName = "?ReportID", SourceColumn = "ReportID" });
OdbcCommand updateCommand = _connection.CreateCommand();
updateCommand.CommandText = @"
UPDATE 
myTable 
SET 
ReportID = ?ReportID
WHERE ID = ?ID";
_dataAdapter.UpdateCommand = updateCommand;
_dataAdapter.UpdateCommand.Parameters.Add(new OdbcParameter { ParameterName = "?ID", SourceColumn = "ID"});
_dataAdapter.UpdateCommand.Parameters.Add(new OdbcParameter { ParameterName = "?ReportID", SourceColumn = "ReportID"});

Anyway, here's the issue. When I call _dataAdapter.Update(_table) it works on inserts, but throws an error on Updates. It says: ERROR [22018][SYBASE][ODBC Syb开发者_如何学Pythonase driver][SQL Server]Implicit conversion from datatype 'NUMERIC' to 'VARCHAR' is not allowed. Use the CONVERT function to run this query.

Examining the variables, there's no reason for this to be happening. ReportID is a varchar, but for some odd reason treated like a numeric on updates. Why is this happening?

UPDATE

Just figured out that it's due to the order I was setting up the parameters. I thought I'd post this anyway just in case someone else gets stuck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜