不使用链接字符串链接数据库,何解?

V0lD V0lD 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
如何不使用链接字符串链接数据库:(这里是登陆界面里的相关代码)
如下代码:
namespace friendship
{
#region 数据库连接类
class Fconnection
{

public SqlConnection SQlconnection()//数据库连接
{
SqlConnection con = new SqlConnection();
Properties.Settings s = Properties.Settings.Default;
con.ConnectionString = s.sqlconnection;
return con;
}
}
#endregion
}


namespace friendship
{
class use
{
private SqlConnection cn = null;
public SqlDataReader dr = null;

#region//登录信息
public int load(userload user)
{
int intfal = 0;

try
{
Fconnection fcn = new Fconnection();
cn = fcn.SQlconnection();
cn.Open();
//str = "select userName,userPassword from user where userName='" + user.User + "'and userpasswoed'" + user.Pwd + "'";
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.Parameters.Add("@userName", SqlDbType.Char);
cmd.Parameters["@userName"].Value = user.User;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "P_load";

dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
intfal = 1;
}
return intfal;
}
catch (Exception ex)
{
return 0;
}

#endregion
}
}
}


在登陆界面的"登陆"按钮中调用这两个类,通过判断use类返回的值,来确定是否链接到数据库,从而进入登陆界面后的操作的.

请问,为何?即没用到链接字符串就能链接数据库了.
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
V0lD
C# 111,129 成员 642,538 内容