new SqlParameter("@UserId", order.User.Id) 这种是什么用法啊?能行?
SqlCommand 的参数类型能不写?new SqlParameter("@UserId", order.User.Id) 直接写名称和数值 也能行?
SqlCommand 的参数怎么写 那些能省?
小弟疑惑啊 求解
设置一个等待执行的SqlCommand对象
/// </summary>
/// <param name="cmd">SqlCommand 对象,不允许空对象</param>
/// <param name="conn">SqlConnection 对象,不允许空对象</param>
/// <param name="commandText">Sql 语句</param>
/// <param name="cmdParms">SqlParameters 对象,允许为空对象</param>
private static void PrepareCommand(SqlCommand cmd, CommandType commandType, SqlConnection conn, string commandText, SqlParameter[] cmdParms)
{
//打开连接
if (conn.State != ConnectionState.Open)
conn.Open();
//设置SqlCommand对象
cmd.Connection = conn;
cmd.CommandText = commandText;
cmd.CommandType = commandType;
if (cmdParms != null)
{
foreach (SqlParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
}
这个代码 Parameters没values啊 Parameters SqlParameter --------------------编程问答--------------------
public static ExecuteResult CreateModel(CreateAppUserParas dataModel)
{
string sqlStatement = @"INSERT INTO AppUser (LoginName,...) VALUES (@LoginName,..);
SELECT @@IDENTITY;";
SqlCommand command = new SqlCommand();
command.CommandText = sqlStatement;
command.Parameters.Add("@LoginName", SqlDbType.NVarChar, 50).Value = dataModel.LoginName;
command.Parameters.Add("@UserID", SqlDbType.Int).Value = dataModel.UserID;
command.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = CreateAppUserParas.Email;
command.Parameters.Add("@Mobile", SqlDbType.NVarChar, 50).Value = CreateAppUserParas.Mobile;
return DBProvider.DefaultDBOperator.ExecuteScalar(command);
}
最主要是算易做图确,这一点哪能什么省?要考虑就花在设计与算法上
补充:.NET技术 , C#