用户登录验证问题----请高手帮忙
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错误,
请高手指点一下