Sql 命令构造
我已经按如下方式构建了 Sql 命令:
string _InsertVehicleQuery = "INSERT INTO VSI_VehicleRecords(StockNumber,Status,Make,Model,Colour,Spefication) VALUES (@StockNumber, @Status, '@Make', '@Model', '@Colour', '@Specification');";
SqlCommand _InsertVehicleCommand = new SqlCommand(_InsertVehicleQuery);
_InsertVehicleCommand.Parameters.Add(new SqlParameter("@StockNumber", __StockNumber));
_InsertVehicleCommand.Parameters.Add(new SqlParameter("@Status", __Status));
_InsertVehicleCommand.Parameters.Add(new SqlParameter("@Make", Make));
_InsertVehicleCommand.Parameters.Add(new SqlParameter("@Model", Model));
_InsertVehicleCommand.Parameters.Add(new SqlParameter("@Colour", Colour));
_InsertVehicleCommand.Parameters.Add(new SqlParameter("@Specification", Specification));
Sql 命令执行
//Method call
DataUtility.NonQuery(_InsertVehicleCommand);
//Method structure
public static void NonQuery(SqlCommand Command)
{
Command.Connection = __Connection;
OpenConnection();
Command.ExecuteNonQuery();
CloseConnection();
}
在 SQL 查询的执行或构造中,我没有做任何明显的事情。我在数据库表中得到的结果:
VehicleRecordID StockNumber Status Make Model Colour Spefication
1 -1 0 @Make @Model @Colour @Specification
在此先感谢您的任何解决方案,也欢迎任何建议!