📄 linkdatabase.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
namespace 进销存管理系统
{
/// <summary>
/// LinkDataBase 的摘要说明。
/// </summary>
public class LinkDataBase
{
private string strSQL;
//与SQL Server的连接字符串设置
private string connectionString = "workstation id=localhost;Integrated Security=SSPI;database=jxcbook";
private SqlConnection myConnection;
private SqlCommandBuilder sqlCmdBld;
private DataSet ds = new DataSet();
private SqlDataAdapter da;
public LinkDataBase()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//根据输入的SQL语句检索数据库数据
public DataSet SelectDataBase(string tempStrSQL,string tempTableName)
{
this.strSQL = tempStrSQL;
this.myConnection = new SqlConnection(connectionString);
this.da = new SqlDataAdapter(this.strSQL,this.myConnection);
this.ds.Clear();
this.da.Fill(ds,tempTableName);
return ds;
}
//数据库数据更新
public DataSet UpdateDataBase(DataSet changedDataSet,string tableName)
{
this.myConnection = new SqlConnection(connectionString);
this.da = new SqlDataAdapter(this.strSQL,this.myConnection);
this.sqlCmdBld = new SqlCommandBuilder(da);
this.da.Update(changedDataSet,tableName);
return changedDataSet;
}
//检索数据库数据(
public DataTable SelectDataBase(string tempStrSQL)
{
this.myConnection = new SqlConnection(connectionString);
DataSet tempDataSet = new DataSet();
this.da = new SqlDataAdapter(tempStrSQL,this.myConnection);
this.da.Fill(tempDataSet);
return tempDataSet.Tables[0];
}
//数据库数据更新
public int UpdateDataBase(string tempStrSQL)
{
this.myConnection = new SqlConnection(connectionString);
myConnection.Open();
SqlCommand tempSqlCommand = new SqlCommand(tempStrSQL,this.myConnection);
int intNumber = tempSqlCommand.ExecuteNonQuery();
myConnection.Close();
return intNumber;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -