(完整版)小型超市收银系统的设计与实现毕业设计论文 下载本文

this.msqlDa.Fill(tempDataSet); return tempDataSet.Tables[0]; }

数据库数据更新(传字符串,直接操作数据库) public int UpdateDataBase(string tempStrSql) {

this.msqlCon = new SqlConnection(mstrCon); msqlCon.Open();

SqlCommand temSqlCmd = new SqlCommand(tempStrSql, msqlCon);

int intNumber = temSqlCmd.ExecuteNonQuery();返回数据库中影响的行数

msqlCon.Close(); return intNumber; }

返回DataSet,检索数据库,传入字符串,及表名称, public DataSet SelectDataBase(string tempStrSQL, string tempTableName) {

this.strSQL = tempStrSQL;

this.msqlCon = new SqlConnection(mstrCon); this.msqlDa = new SqlDataAdapter(this.strSQL, this.msqlCon);

if (mds.Tables.Contains(tempTableName) == true) {

this.mds.Tables[tempTableName].Clear(); }

this.msqlDa.Fill(mds, tempTableName); return mds; }

保持DataSet和数据库的同步更新

public DataSet UpdateDataBase(DataSet changedDataSet,string tableName) {

this.msqlCon = new SqlConnection(mstrCon); this.msqlDa = new SqlDataAdapter(this.strSQL, this.msqlCon);

this.msqlCmdBld = new SqlCommandBuilder(msqlDa); this.msqlDa.Update(changedDataSet, tableName); if (changedDataSet.Tables.Contains(tableName) == true) {

changedDataSet.Tables[tableName].Clear(); }

msqlDa.Fill(changedDataSet, tableName); return changedDataSet;返回已更新的数据库表 }

用于用户登录验证

public int UserLogin(int userId, string userPwd) {

SqlCommand myCmd = new SqlCommand(\

msqlCon);

myCmdmandType = CommandType.StoredProcedure; 给存储过程添加参数

SqlParameter UserId = new SqlParameter(\SqlDbType.Int, 4);

UserId.Value = userId;

myCmd.Parameters.Add(UserId); 给存储过程添加参数

SqlParameter UserPwd = new SqlParameter(\SqlDbType.NVarChar,10);

UserPwd.Value = userPwd; myCmd.Parameters.Add(UserPwd); 给存储过程添加参数

SqlParameter flag = new SqlParameter(\SqlDbType.Int, 4);

flag.Direction = ParameterDirection.Output; myCmd.Parameters.Add(flag); 执行数据库操作

myCmd.ExecuteNonQuery();

取得存储过程OUTPUT参数的值作为函数的返回值 return Convert.ToInt32(flag.Value); }

插入商品基本信息

public bool AddGoods(GoodsDetails tempGoods) {

this.msqlCon = new SqlConnection(mstrCon);

SqlCommand myCmd = new SqlCommand(\msqlCon);

myCmdmandType = CommandType.StoredProcedure; 给存储过程添加参数

SqlParameter myID = new SqlParameter(\SqlDbType.NVarChar, 20);

myID.Value = tempGoods.GoodsId; myCmd.Parameters.Add(myID);

SqlParameter myName = new

SqlParameter(\ myName.Value = tempGoods.GoodsName; myCmd.Parameters.Add(myName);

SqlParameter myType = new SqlParameter(\SqlDbType.NVarChar, 10);

myType.Value = tempGoods.TypeName; myCmd.Parameters.Add(myType);

SqlParameter myUnit = new SqlParameter(\SqlDbType.NVarChar, 5);

myUnit.Value = tempGoods.GoodsUnit; myCmd.Parameters.Add(myUnit);