SqlParameter用法

Posted asdyzh

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SqlParameter用法相关的知识,希望对你有一定的参考价值。

if (id != null)
{
sql = @"update [User] set Username = @Username, Password = @Password, Type = @UserType, FullName = @FullName, Telephone = @Telephone, Department = @Department where ID=" + id;
}
else
{
sql = @"insert into [User] (Username, Password, Type, FullName, Telephone, Department) values (@Username, @Password, @UserType, @FullName, @Telephone, @Department)";
}

SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter("@UserType", usertype),
new SqlParameter("@Username", sname),
new SqlParameter("@Password", spwd),
new SqlParameter("@FullName", fullname),
new SqlParameter("@Telephone", telephone),
new SqlParameter("@Department", dept)
};
SqlConnection conn = new SqlConnection(scnn);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddRange(parms);
var row = cmd.ExecuteNonQuery();
conn.Close();






















以上是关于SqlParameter用法的主要内容,如果未能解决你的问题,请参考以下文章

SqlParameter防止SQL注入

c#中SqlParameter用法

SqlParameter like

SqlParameter like

将 null 分配给 SqlParameter

SqlParameter的用法