用户登录验证问题----请高手帮忙
login.cs文件
public class loginfrm : System.Windows.Forms.Form
{
public static bool blCanLogin = false; //记录能否检验是否通过
public static string strUser = ""; //记录用户名
public static string strDepartment = "";//记录通过者权限
private DataSet ds = new DataSet();
private DataTable myTable;
private DataRow myRow;
private string sendStrSQL = "SELECT * from sunsoft";
private System.Windows.Forms.TextBox txt_ID;
private System.Windows.Forms.TextBox txt_Pwd;
private System.Windows.Forms.Button btnok;
private System.Windows.Forms.Label lbname;
private System.Windows.Forms.Label lbpw;
private System.Windows.Forms.Button btnquit;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
static void Main()
{
Application.Run(new loginfrm());
}
public loginfrm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
LinkDataBase link = new LinkDataBase();
string sendTableName = "sunsoft1";
this.ds = link.SelectDataBase(sendStrSQL,sendTableName);
this.myTable = ds.Tables[0];
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
private void btnok_Click(object sender, System.EventArgs e)
{
for (int i=0;i<myTable.Rows.Count;i++)
{
this.myRow = myTable.Rows[i];
//只有当输入的用户名和密码同时对应上数据库中记录时,才能通过校验
if (myRow[0].ToString().Trim()==this.txt_ID.Text.ToString().Trim() && myRow[1].ToString().Trim()==this.txt_Pwd.Text.ToString().Trim())
{
blCanLogin = true;
strUser = myRow[0].ToString().Trim();//保存用户名
strDepartment = myRow[1].ToString().Trim();//保存权限
this.Close();//关闭窗体
return;
}
}
MessageBox.Show( "您输入的用户号或密码不正确!","系统提示");
return;
}
LinkDataBase.cs文件中
public class LinkDataBase
{
private string strSQL;
//与SQL Server的连接字符串设置
private string ConnectionString= "Provider=sqloledb;Data Source=web;Initial Catalog=liming;User Id=sa;Password=12345;";
private OleDbConnection myConnection;
private OleDbCommandBuilder OleDbCmdBld;
private DataSet ds = new DataSet();
private OleDbDataAdapter da;
public LinkDataBase()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
///////////////////////////////// 操作脱机数据库(创建了该类的实例时直接用) /////////////////////////////////////////////////////
//根据输入的SQL语句检索数据库数据
public DataSet SelectDataBase(string tempStrSQL,string tempTableName)
{
this.strSQL = tempStrSQL;
this.myConnection = new OleDbConnection(ConnectionString);
this.da = new OleDbDataAdapter(this.strSQL,this.myConnection);
this.ds.Clear();
this.da.Fill(ds,tempTableName);
return ds;//返回填充了数据的DataSet,其中数据表以tempTableName给出的字符串命名
}
//数据库数据更新(传DataSet和DataTable的对象)
public DataSet UpdateDataBase(DataSet changedDataSet,string tableName)
{
this.myConnection = new OleDbConnection(ConnectionString);
this.da = new OleDbDataAdapter(this.strSQL,this.myConnection);
this.OleDbCmdBld = new OleDbCommandBuilder(da);
this.da.Update(changedDataSet,tableName);
return changedDataSet;//返回更新了的数据库表
}
///////////////////////////////// 直接操作数据库(未创建该类的实例时直接用) /////////////////////////////////////////////////////
//检索数据库数据(传字符串,直接操作数据库)
public DataTable SelectDataBase(string tempStrSQL)
{
this.myConnection = new OleDbConnection(ConnectionString);
DataSet tempDataSet = new DataSet();
this.da = new OleDbDataAdapter(tempStrSQL,this.myConnection);
this.da.Fill(tempDataSet);
return tempDataSet.Tables[0];
}
//数据库数据更新(传字符串,直接操作数据库)
public int UpdateDataBase(string tempStrSQL)
{
this.myConnection = new OleDbConnection(ConnectionString);
//使用Command之前一定要先打开连接,后关闭连接,而DataAdapter则会自动打开关闭连接
myConnection.Open();
OleDbCommand tempSqlCommand = new OleDbCommand(tempStrSQL,this.myConnection);
int intNumber = tempSqlCommand.ExecuteNonQuery();//返回数据库中影响的行数
myConnection.Close();
return intNumber;
}
}
}
在本机环境中运行正确,可是到了别人机器上运行出错oledb错误,
请高手指点一下
public class loginfrm : System.Windows.Forms.Form
{
public static bool blCanLogin = false; //记录能否检验是否通过
public static string strUser = ""; //记录用户名
public static string strDepartment = "";//记录通过者权限
private DataSet ds = new DataSet();
private DataTable myTable;
private DataRow myRow;
private string sendStrSQL = "SELECT * from sunsoft";
private System.Windows.Forms.TextBox txt_ID;
private System.Windows.Forms.TextBox txt_Pwd;
private System.Windows.Forms.Button btnok;
private System.Windows.Forms.Label lbname;
private System.Windows.Forms.Label lbpw;
private System.Windows.Forms.Button btnquit;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
static void Main()
{
Application.Run(new loginfrm());
}
public loginfrm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
LinkDataBase link = new LinkDataBase();
string sendTableName = "sunsoft1";
this.ds = link.SelectDataBase(sendStrSQL,sendTableName);
this.myTable = ds.Tables[0];
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
private void btnok_Click(object sender, System.EventArgs e)
{
for (int i=0;i<myTable.Rows.Count;i++)
{
this.myRow = myTable.Rows[i];
//只有当输入的用户名和密码同时对应上数据库中记录时,才能通过校验
if (myRow[0].ToString().Trim()==this.txt_ID.Text.ToString().Trim() && myRow[1].ToString().Trim()==this.txt_Pwd.Text.ToString().Trim())
{
blCanLogin = true;
strUser = myRow[0].ToString().Trim();//保存用户名
strDepartment = myRow[1].ToString().Trim();//保存权限
this.Close();//关闭窗体
return;
}
}
MessageBox.Show( "您输入的用户号或密码不正确!","系统提示");
return;
}
LinkDataBase.cs文件中
public class LinkDataBase
{
private string strSQL;
//与SQL Server的连接字符串设置
private string ConnectionString= "Provider=sqloledb;Data Source=web;Initial Catalog=liming;User Id=sa;Password=12345;";
private OleDbConnection myConnection;
private OleDbCommandBuilder OleDbCmdBld;
private DataSet ds = new DataSet();
private OleDbDataAdapter da;
public LinkDataBase()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
///////////////////////////////// 操作脱机数据库(创建了该类的实例时直接用) /////////////////////////////////////////////////////
//根据输入的SQL语句检索数据库数据
public DataSet SelectDataBase(string tempStrSQL,string tempTableName)
{
this.strSQL = tempStrSQL;
this.myConnection = new OleDbConnection(ConnectionString);
this.da = new OleDbDataAdapter(this.strSQL,this.myConnection);
this.ds.Clear();
this.da.Fill(ds,tempTableName);
return ds;//返回填充了数据的DataSet,其中数据表以tempTableName给出的字符串命名
}
//数据库数据更新(传DataSet和DataTable的对象)
public DataSet UpdateDataBase(DataSet changedDataSet,string tableName)
{
this.myConnection = new OleDbConnection(ConnectionString);
this.da = new OleDbDataAdapter(this.strSQL,this.myConnection);
this.OleDbCmdBld = new OleDbCommandBuilder(da);
this.da.Update(changedDataSet,tableName);
return changedDataSet;//返回更新了的数据库表
}
///////////////////////////////// 直接操作数据库(未创建该类的实例时直接用) /////////////////////////////////////////////////////
//检索数据库数据(传字符串,直接操作数据库)
public DataTable SelectDataBase(string tempStrSQL)
{
this.myConnection = new OleDbConnection(ConnectionString);
DataSet tempDataSet = new DataSet();
this.da = new OleDbDataAdapter(tempStrSQL,this.myConnection);
this.da.Fill(tempDataSet);
return tempDataSet.Tables[0];
}
//数据库数据更新(传字符串,直接操作数据库)
public int UpdateDataBase(string tempStrSQL)
{
this.myConnection = new OleDbConnection(ConnectionString);
//使用Command之前一定要先打开连接,后关闭连接,而DataAdapter则会自动打开关闭连接
myConnection.Open();
OleDbCommand tempSqlCommand = new OleDbCommand(tempStrSQL,this.myConnection);
int intNumber = tempSqlCommand.ExecuteNonQuery();//返回数据库中影响的行数
myConnection.Close();
return intNumber;
}
}
}
在本机环境中运行正确,可是到了别人机器上运行出错oledb错误,
请高手指点一下
...全文
相关推荐
通达 2017版微信token信息变更后提示“您的登录账户有问题,请验证后再登录”兼容包
通达 2017版微信token信息变更后提示“您的登录账户有问题,请验证后再登录”兼容包
用户登录之token验证
1.场景还原 可能还有很多小伙伴对token概念朦朦胧胧,今天笔者以项目中的用户登录的token验证需求跟大家讲讲其中的来龙去脉,希望能够理清大伙的思路。 2.需求分析 这个需求可能早已是老生常谈,但我觉得它永远也不会过时 ①谷歌浏览器:login.html---->index.html; ②然后复制index.html的地址在IE浏览器地址栏上,这时普遍网站都会使访问界面直接
C#用户登录验证代码
初学c#大家多多指教。
python实现网站用户名密码自动登录功能
最近接到这样的需求通过网页用户认证登录实现上网,如何实现网站自动登录功能呢,接下来小编给大家带来了python实现网站用户名密码自动登录功能,需要的朋友可以参考下
Q702950 问题的回答 c#winform登录后其用户名显示在另一窗体的文本框中
Q702950 问题的回答 c#winform登录后其用户名显示在另一窗体的文本框中 https://ask.csdn.net/answers/593571


