在文件夹BusinessLogicLayer放了DataAccessLayer.cs代码如下:
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Diagnostics;
using System.ComponentModel;
namespace WebSite1.DataAcessLayer
{
public class Database : IDissposable
{
protected SqlConnection Connection; protected String ConnectionString; public Database()
{
ConnectionString = ConfigurationSettings.AppSettings["DBConnectionString"];
} ~Database()
{
try
{
if (Connection != null)
{
Connection.Close();
}
}catch { }
try
{ }
catch{ }
}
protected void open()
{
if(Connection == null)
{
Connection = new SqlConnection(ConnectionString);
}
if(Connection.State.Equals(ConnectionState.Closed))
{
Connection.Open();
}
}
public void Close()
{
if (Connection != null)
{
Connection.Close();
}
}
public void Dispose()
{
if(Connection !=null)
{
Connection.Dispose();
Connection = null;
}
}
public int ExecuteSQL(String SqlString)
{
int count = -1;
Open();
try
{
SqlCommand cmd = new SqlCommand(SqlString, Connection);
count = cmd.exectenonquery(); }
catch
{
count = -1; }
finally
{
Close();
}
return count;
}
public DataSet GetDataSet(String SqlString)
{
open();
SqlDataAdapter adapter = new SqlDataAdapter(SqlString, Connection);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
Close();
return dataset;
}
public DataRoow GetDAtaRow(String SqlString)
{
DataSet dataset = GetDataSet(SqlString);
dataset.casesitive = false;
if(dataset.Tables[0].Rows.Count>0)
{
return dataset.Tables[0].Rows[0];
}
else
{
return null;
}
} }
}
我在文件夹BusinessLogicLayer放了User.cs代码如下:
using System;
using System.Data;using WebSite1.DataAccessLayer;
namespace WebSite1.BusinessLogicLayer
{
public class User
{
private string _userName;
private string _password; private bool _exist; public string UserName
{
set
{
this._userName = value;
}
get
{
return this._userName;
}
} public string password
{
set
{
this._password = value;
}
get
{
return this._password;
}
} public bool Exist
{
get
{
return this._exist;
}
}
public void LoadData(string userName)
{
Database db = new Database();
string sql = "select * from [User] where UserName = '" + userName + "'";
DataRow dr = db.GetDataRow(sql);
if (dr != null)
{
this._userName = dr["UserName"].ToString();
this._password = dr["Password"].ToString();
}
else
this._exist = false; }
public void Add(string username, string password)
{
Database db = new Database();
string sql= "insert into [User] values("+"'"+username+"',"+"'"+password+"')";
db.ExecuteSQL(sql);
}
}
}
问题:为什么不能引用到Database.cs类???
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Diagnostics;
using System.ComponentModel;
namespace WebSite1.DataAcessLayer
{
public class Database : IDissposable
{
protected SqlConnection Connection; protected String ConnectionString; public Database()
{
ConnectionString = ConfigurationSettings.AppSettings["DBConnectionString"];
} ~Database()
{
try
{
if (Connection != null)
{
Connection.Close();
}
}catch { }
try
{ }
catch{ }
}
protected void open()
{
if(Connection == null)
{
Connection = new SqlConnection(ConnectionString);
}
if(Connection.State.Equals(ConnectionState.Closed))
{
Connection.Open();
}
}
public void Close()
{
if (Connection != null)
{
Connection.Close();
}
}
public void Dispose()
{
if(Connection !=null)
{
Connection.Dispose();
Connection = null;
}
}
public int ExecuteSQL(String SqlString)
{
int count = -1;
Open();
try
{
SqlCommand cmd = new SqlCommand(SqlString, Connection);
count = cmd.exectenonquery(); }
catch
{
count = -1; }
finally
{
Close();
}
return count;
}
public DataSet GetDataSet(String SqlString)
{
open();
SqlDataAdapter adapter = new SqlDataAdapter(SqlString, Connection);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
Close();
return dataset;
}
public DataRoow GetDAtaRow(String SqlString)
{
DataSet dataset = GetDataSet(SqlString);
dataset.casesitive = false;
if(dataset.Tables[0].Rows.Count>0)
{
return dataset.Tables[0].Rows[0];
}
else
{
return null;
}
} }
}
我在文件夹BusinessLogicLayer放了User.cs代码如下:
using System;
using System.Data;using WebSite1.DataAccessLayer;
namespace WebSite1.BusinessLogicLayer
{
public class User
{
private string _userName;
private string _password; private bool _exist; public string UserName
{
set
{
this._userName = value;
}
get
{
return this._userName;
}
} public string password
{
set
{
this._password = value;
}
get
{
return this._password;
}
} public bool Exist
{
get
{
return this._exist;
}
}
public void LoadData(string userName)
{
Database db = new Database();
string sql = "select * from [User] where UserName = '" + userName + "'";
DataRow dr = db.GetDataRow(sql);
if (dr != null)
{
this._userName = dr["UserName"].ToString();
this._password = dr["Password"].ToString();
}
else
this._exist = false; }
public void Add(string username, string password)
{
Database db = new Database();
string sql= "insert into [User] values("+"'"+username+"',"+"'"+password+"')";
db.ExecuteSQL(sql);
}
}
}
问题:为什么不能引用到Database.cs类???
解决方案 »
- 怎么解决一个方法被不同调用者同时访问问题?
- this.Context.Parameters["targetdir"]//获得值是空值????????
- 70分 求助 解决即结贴
- 如果谁用.net能做这样的系统,那我就服了他了
- 关于DATASET被填充后数据的显示问题。。。。
- 急求资源,有关窗体设计器风格的程序
- 想换工作不
- 怎样在自定义的组件中定义代码,使该组件在注册时能够自动增加到工具箱中某个指定的Tab项中,而不是当前工具箱项
- Console.WriteLine();装箱问题
- 请问这段Request Payload要怎么用C#传递?
- 借用[jinjazz]创意的攒分贴 之 初学WPF遇到一些问题
- 显示等待信息问题
是否放在 app_code 里面
再试试