码迷,mamicode.com
首页 > 数据库 > 详细

SqlParameter用法

时间:2018-10-06 00:05:33      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:comm   word   update   pass   HERE   val   scn   row   date   

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用法

标签:comm   word   update   pass   HERE   val   scn   row   date   

原文地址:https://www.cnblogs.com/asdyzh/p/9746323.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!