📄 billdailys.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Common;
namespace DataAccess
{
public class BillDailys
{
private readonly string connection = "server=.;database=homemoney;uid=sa;pwd=";
private readonly string tableName = "T_BillDaily";
public string TableName
{
get { return tableName; }
}
private SqlDataAdapter dataAdapter = null;
private SqlConnection cn = null;
public SqlConnection Connection
{
get
{
if (cn == null || cn.State == ConnectionState.Closed)
cn = new SqlConnection(connection);
return cn;
}
}
public DataSet GetBillDailys( string sql)
{
//要返回的数据集
DataSet ds = new DataSet();
if (dataAdapter == null) dataAdapter = new SqlDataAdapter(sql, connection);
try
{
dataAdapter.Fill(ds, this.tableName);
}
catch (SqlException e)
{
Logger.Log(e.Message);
}
return ds;
}
public bool Delete(DataSet ds, SqlCommand cmd)
{
try
{
dataAdapter.DeleteCommand = cmd;
dataAdapter.Update(ds, this.tableName);
cn.Close();
}
catch (SqlException e)
{
Logger.Log(e);
return false;
}
return true;
}
public bool Update(DataSet ds, SqlCommand cmd)
{
try
{
dataAdapter.UpdateCommand = cmd;
dataAdapter.Update(ds, this.tableName);
cn.Close();
}
catch (SqlException e)
{
Logger.Log(e);
return false;
}
return true;
}
public bool Insert(BillDaily t)
{
//构造插入数据的SQL语句
string sql= string.Format("INSERT INTO T_BillDaily VALUES({0},{1},{2},'{3}','{4}','{5}','{6}',{7})",
t.BAID, t.BDINMoney, t.BDOUTMoney, t.BDItem, t.BDDate, t.BDUser, t.BDRemarks, t.BDBalance
);
SqlCommand cmd = new SqlCommand(sql, Connection);
try
{
//插入数据库
cmd.Connection.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException e)
{
Logger.Log(e.Message);
return false;
}
finally
{
cmd.Connection.Close();
}
return true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -