求大神指教数据库链接问题
用VS2005与SQL的数据库进行连接,编一个登陆窗口,,哪位大神给出具体点代码
[解决办法]
<connectionStrings>
<add name="ConnectionString" providerName="System.Data.SqlClient" connectionString="server=localhost\SQLEXPRESS;database=数据库名;uid=sa;pwd=12345"/>
</connectionStrings>
protected void btn_OK_Click(object sender, EventArgs e)
{
AppUser user = AppSettingSRV.VerifyPassword(loginName, password);
if (user == null)
{
AppUser loginUser = AppSettingSRV.GetAppUserByLoginName(loginName);
this.LoginFail.InnerText = (loginUser == null ? "用戶不存在." : "密码错误.");
}
else
{
this.LoginFail.InnerText = "登录成功";
}
}
public static AppUser GetAppUserByLoginName(string loginName)
{
AppUserORM user = AppUserController.GetAppUserByLoginName(loginName);
if (user == null)
{
return null;
}
return user.ConvertAppUserORMToEDM();
}
public static AppUserORM GetAppUserByLoginName(string loginName)
{
string sql = "SELECT * FROM AppUser WHERE LoginName = @LoginName";
SqlCommand command = new SqlCommand(sql);
command.Parameters.Add("@LoginName", SqlDbType.NVarChar).Value = loginName;
DataTable table = DBProvider.DefaultDBOperator.GetDataTable(command);
if (table.Rows.Count == 0)
{
return null;
}
return table.Rows[0].ConvertToDBModel<AppUserORM>();
}