主题:求助
//一个数据访问层的例子,该类并不需要从数据库中检索数据,
//只是删除库表中的一些记录,或添加一些记录,请帮忙优化,或指出不足
class DataAccess
{
private OleDbConnection Conn;
private OleDbDataAdapter DALab;
private DataTable tblRawData;
public DataAccess(string strconn)
{
Conn = new OleDbConnection(strconn);
Conn.Open();
DALab = new OleDbDataAdapter("select * from lab_rawdata", Conn);
tblRawData = new DataTable("lab_rawdata");
DALab.FillSchema(tblRawData, SchemaType.Source);//并不需要检索记录
Conn.Close();
}
public void AddNew(string Sample,string Item,decimal Result)
{
DataRow drCurrent = tblRawData.NewRow();
drCurrent["sample_id"] = Sample;
drCurrent["item_code"] = Item;
drCurrent["result"] = Result;
tblRawData.Rows.Add(drCurrent);
}
public void DelRows(string Sample)
{
Conn.Open();
string strDel = "delete from lab_rawdata where sample_id = " + Sample;
OleDbCommand mycommand = new OleDbCommand(strDel, Conn);
mycommand.ExecuteNonQuery();
Conn.Close();
}
public void UpDate()
{
DALab.Update(tblRawData );
tblRawData.Clear();
tblRawData.AcceptChanges();
}
}
//只是删除库表中的一些记录,或添加一些记录,请帮忙优化,或指出不足
class DataAccess
{
private OleDbConnection Conn;
private OleDbDataAdapter DALab;
private DataTable tblRawData;
public DataAccess(string strconn)
{
Conn = new OleDbConnection(strconn);
Conn.Open();
DALab = new OleDbDataAdapter("select * from lab_rawdata", Conn);
tblRawData = new DataTable("lab_rawdata");
DALab.FillSchema(tblRawData, SchemaType.Source);//并不需要检索记录
Conn.Close();
}
public void AddNew(string Sample,string Item,decimal Result)
{
DataRow drCurrent = tblRawData.NewRow();
drCurrent["sample_id"] = Sample;
drCurrent["item_code"] = Item;
drCurrent["result"] = Result;
tblRawData.Rows.Add(drCurrent);
}
public void DelRows(string Sample)
{
Conn.Open();
string strDel = "delete from lab_rawdata where sample_id = " + Sample;
OleDbCommand mycommand = new OleDbCommand(strDel, Conn);
mycommand.ExecuteNonQuery();
Conn.Close();
}
public void UpDate()
{
DALab.Update(tblRawData );
tblRawData.Clear();
tblRawData.AcceptChanges();
}
}