Asp.Mvc 2.0用户登录实例讲解---(1)用户注册(8)
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
namespace MvcLogin.Models
{
public class SqlHelper
{
//数据库连接字符串
readonly string conStr = "server=.;uid=sa;pwd=123;database=cztest;Min Pool Size=10;";
string strAdd = @"INSERT INTO dbo.UserInfo
( UserName, UserPwd, Email )
VALUES ( '{0}', -- UserName - varchar(20)
'{1}', -- UserPwd - varchar(20)
'{2}' -- Email - varchar(50)
)";
string strUserExist = @" SELECT * FROM dbo.UserInfo WHERE UserName='{0}' AND UserPwd='{1}'";
/// <summary>
/// 添加用户
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool AddUser(RegisterModel model)
{
strAdd = string.Format(strAdd, model.UserName, model.UserPwd, model.Email);
SqlConnection con = new SqlConnection(conStr);
con.Open();
SqlCommand cmd = new SqlCommand(strAdd,con);
int o = cmd.ExecuteNonQuery();
con.Close();
if (o>0)
{
return true;
}
return false;
}
/// <summary>
/// 判断用户是否存在
/// </summary>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>