嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
Excel做为数据库登录的三层实现
一个简单的登录验证程序源码,数据库采用的是Excel,利用简单三层实现
DB/users.xls为Excel文件
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
using System.Configuration;
namespace SQLHelper
{
public class SqlOpe
{
private OleDbConnection myConnection = null;
private void Open()
{
if (myConnection == null)
myConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\\users.xls;Extended Properties=Excel 8.0;");
if (myConnection.State == ConnectionState.Closed)
{
try
{
///打开数据库连接
myConnection.Open();
}
catch (Exception ex)
{
}
finally
{
///关闭已经打开的数据库连接
}
}
}
public void Close()
{
///判断连接是否已经创建
if (myConnection != null)
{
///判断连接的状态是否打开
if (myConnection.State == ConnectionState.Open)
{
myConnection.Close();
}
}
}
public void Dispose()
{
// 确认连接是否已经关闭
if (myConnection != null)
{
myConnection.Dispose();
myConnection = null;
}
}
public void RunSQL(string cmdText,out OleDbDataReader dataReader)
{
Open();
OleDbCommand cmd = new OleDbCommand(cmdText,myConnection);
//cmd.Parameters.Add(new OleDbParameter(RETURNVALUE, OleDbType.Integer, 4, ParameterDirection.ReturnValue,
// false, 0, 0, string.Empty, DataRowVersion.Default, null));
try
{
///读取数据
dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
//dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (Exception ex)
{
dataReader = null;
///记录错误日志
//SystemError.CreateErrorLog(ex.Message);
//Close();
}
finally
{
//Close();
}
}
}
}