⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbserver.cs

📁 c#can yin guan li xi tong
💻 CS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -