dbserver.cs
来自「c#can yin guan li xi tong」· CS 代码 · 共 71 行
CS
71 行
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace 餐饮管理系统
{
class DBserver
{
static string ConnectionString = "server=.;Trusted_Connection=yes;database=餐饮管理系统;";
//方法一,返回一个表
public static DataTable setComGetTable(string strSql)
{
DataTable dt = new DataTable();
try
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(strSql, conn);
da.Fill(ds);
conn.Close();
if (ds.Tables.Count > 0)
dt = ds.Tables[0];
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
return dt;
}
public static object setCommGetScalar(string strSql)
{
object ObjOut = "";
try
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
SqlCommand comm = new SqlCommand(strSql, conn);
ObjOut = comm.ExecuteScalar();
conn.Close();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
return ObjOut;
}
//方法二,无返回值
public static int setCommNornQuey(string strSql)
{
int nResult = -1;
try
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
SqlCommand comm = new SqlCommand(strSql, conn);
nResult = comm.ExecuteNonQuery();
conn.Close();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
return nResult;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?