1 Star 0 Fork 177

ai4china/蜀味正道(餐饮)

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
SqlDB.cs 3.83 KB
一键复制 编辑 原始数据 按行查看 历史
kbz 提交于 2022-03-25 08:56 . submint
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DA
{
class SqlDB
{
public static string sConn = System.Configuration.ConfigurationManager.ConnectionStrings["TeaManageConnectionString"].ConnectionString;
public static SqlConnection con = new SqlConnection(sConn);
/// <summary>
/// 返回SqlCommand
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static SqlCommand sqlCom(string sql)
{
SqlCommand com = new SqlCommand(sql, con);
return com;
}
/// <summary>
/// 返回SqlDataAdapter
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static SqlDataAdapter sqlDa(string sql)
{
SqlDataAdapter da = new SqlDataAdapter(sqlCom(sql));
return da;
}
/// <summary>
/// 增删改方法
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static bool ExcuteSql(string sql)
{
SqlConnection conn = new SqlConnection(sConn);
SqlCommand com = new SqlCommand();
com.Connection = conn;
com.CommandText = sql;
int result = -1;
conn.Open();
try
{
result = com.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
finally
{
conn.Close();
}
}
/// <summary>
/// 查询方法
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static DataSet Query(string sql)
{
SqlDataAdapter sda = new SqlDataAdapter(sql, sConn);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds;
}
//处理存储过程
public static bool ExcutePro(string proName, SqlParameter[] ss)
{
SqlConnection con = new SqlConnection(sConn);
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = proName; //pro_insertOne
//处理参数
foreach (SqlParameter s in ss)
{
com.Parameters.Add(s);
}
int isSuccess = -1;
con.Open();
try
{
isSuccess = com.ExecuteNonQuery();
if (isSuccess > 0)
{
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
finally
{
con.Close();
}
}
//方法的重载
public static string ExcutePro(string proName, SqlParameter ss)
{
SqlConnection con = new SqlConnection(sConn);
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = proName; //pro_insertOne
//处理参数
com.Parameters.Add(ss);
string newId;
con.Open();
try
{
com.ExecuteNonQuery();
newId = com.Parameters[0].Value.ToString();
}
catch
{
newId = null;
}
finally
{
con.Close();
}
return newId;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/ai4china/foodApp.git
[email protected]:ai4china/foodApp.git
ai4china
foodApp
蜀味正道(餐饮)
master

搜索帮助