📄 operator.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace BMS
{
class Operator
{
//通用的SELECT功能
public static DataSet SelectSql(string sqlSelect)
{
SqlConnection con = DB.getcon();
SqlDataAdapter sda = new SqlDataAdapter(sqlSelect, con);
DataSet ds = new DataSet();
try
{
sda.Fill(ds);
}
catch (SqlException e)
{
throw new Exception(e.Message);
}
return ds;
}
//通用的对数据进行添加,修改,删除的功能
public static int ExecuteSql(string sql)
{
int rows = -1;
SqlConnection con = DB.getcon();
SqlCommand cmd = new SqlCommand(sql, con);
try
{
con.Open();
string str = con.State.ToString();
rows = cmd.ExecuteNonQuery();
}
catch (SqlException e)
{
throw new Exception(e.Message);
}
finally
{
cmd.Dispose();
con.Close();
}
return rows;
}
//将选择的值读到指定的文本框中去
public static SqlDataReader fill(string strSQL)
{
SqlConnection con = DB.getcon();
SqlCommand cmd = new SqlCommand(strSQL, con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
return reader;
}
//通用返回行数的功能
public static int select(string strSQL)
{
int rows = -1;
SqlConnection con = DB.getcon();
SqlCommand cmd = new SqlCommand(strSQL, con);
try
{
con.Open();
rows = Convert.ToInt32(cmd.ExecuteScalar());
}
catch (SqlException e)
{
throw new Exception(e.Message);
}
finally
{
cmd.Dispose();
con.Close();
}
return rows;
}
public static DataTable Datafill(string sqlSelect)//DataSet SelectSql
{
SqlConnection con = DB.getcon();
SqlDataAdapter sda = new SqlDataAdapter(sqlSelect, con);
DataTable ds = new DataTable();
try
{
sda.Fill(ds);
}
catch (SqlException e)
{
throw new Exception(e.Message);
}
return ds;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -