展开全部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace MyKTV
{
class DBHelper
{
private string connstr = string.Format("Data Source=服务器名;Initial Catalog=MyKTV(数据库名);User ID=用户名;Pwd=密码");//如果是windows登陆就写(Integrated Security=True),服务器名本机可用(.)点,没有密码Pwd可以不写,
private SqlConnection connection;
public SqlConnection Connection
{
get
{
if (connection == null)
{
connection = new SqlConnection(connstr);
}
return connection;
}
}
public void OpenConnection()
{
if (Connection.State == ConnectionState.Closed)
{
Connection.Open();
}
else if (Connection.State == ConnectionState.Broken)
{
Connection.Close();
Connection.Open();
}
}
public void CloseConnection()
{
if (Connection.State == ConnectionState.Open || Connection.State == ConnectionState.Broken)
{
Connection.Close();
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace MyKTV
{
class DBHelper
{
private string connstr = string.Format("Data Source=服务器名;Initial Catalog=MyKTV(数据库名);User ID=用户名;Pwd=密码");//如果是windows登陆就写(Integrated Security=True),服务器名本机可用(.)点,没有密码Pwd可以不写,
private SqlConnection connection;
public SqlConnection Connection
{
get
{
if (connection == null)
{
connection = new SqlConnection(connstr);
}
return connection;
}
}
public void OpenConnection()
{
if (Connection.State == ConnectionState.Closed)
{
Connection.Open();
}
else if (Connection.State == ConnectionState.Broken)
{
Connection.Close();
Connection.Open();
}
}
public void CloseConnection()
{
if (Connection.State == ConnectionState.Open || Connection.State == ConnectionState.Broken)
{
Connection.Close();
}
}
}
}
展开全部
string connstr = @"Data Source=.\sqlexpress;Initial Catalog=数据库名;Integrated Security=True";
SqlConnection conn = new SqlConnection(connstr);
string sql = "select * from admin where username='" + user + "' and pwd='" + pwd + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
int x=cmd.ExecuteNonQuery();
if (x > 0)
{
//登陆成功!
}
else
{
//登陆失败!
}
SqlConnection conn = new SqlConnection(connstr);
string sql = "select * from admin where username='" + user + "' and pwd='" + pwd + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
int x=cmd.ExecuteNonQuery();
if (x > 0)
{
//登陆成功!
}
else
{
//登陆失败!
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
string slts = "select UserPassword from PersonInfo where UserName='" + username + "' and Admin='" + Ad + "'";
DataSet ds = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(str, CommandType.Text, slts);
if (ds.Tables[0].Rows.Count > 0)
{
string password = ds.Tables[0].Rows[0]["UserPassword"].ToString();
if (password == rpw)
{
Response.Redirect(Dr);
}
}
DataSet ds = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(str, CommandType.Text, slts);
if (ds.Tables[0].Rows.Count > 0)
{
string password = ds.Tables[0].Rows[0]["UserPassword"].ToString();
if (password == rpw)
{
Response.Redirect(Dr);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询