SqlCommand,OracleCommand,OleDbCommand 或 OdbcCommand比较

4种连接方式异同比较

SqlCommand.Parameters中的参数变量要在前面加“@

如:myCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers WHERE Country = @Country AND City = @City";OracleCommand.Parameters中的參數變量要在前面加“:”如:myCommand.CommandText = "UPDATE test SET test1 =:test1, test2 =:test2 WHERE id = :id";OleDbCommand 或 OdbcCommand 为“?”
如:myCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers WHERE Country = ? AND City = ?";

所以,需要注意:

OracleCommand oCmd = new OracleCommand();

oCmd.CommandText = "SELECT * FROM table WHERE Col = :Col ORDER BY Col2";

oCmd.Parameters.Add("Col",col);

而连接SQLServer:

SqlCommand sqlCmd = new SqlCommand();

sqlCmd .CommandText = "SELECT * FROM table WHERE Col = @Col ORDER BY Col2";

sqlCmd .Parameters.Add("@Col",col);

posted on 2009-11-30 10:44  highmayor  阅读(573)  评论(0编辑  收藏  举报

导航