2 Star 1 Fork 0

hff/POSTSQLNET

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Program.cs 2.92 KB
一键复制 编辑 原始数据 按行查看 历史
hff 提交于 2019-06-19 16:32 +08:00 . 新增调用存储过程

using Npgsql;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PGDemo
{
class Program
{
static void Main(string[] args)
{
var strSql = "select * from sys_user";
var dtTemp = PGDBHelper.PostgreTable(strSql);
strSql = "select id from temp_test ";
var str = PGDBHelper.GetpostgreExecuteScalar(strSql);
strSql = "update temp_test set name='wwwwwwww' where id='1122'";
var flag = PGDBHelper.PostgreExecuQuery(strSql);
}
public class PGDBHelper
{
public static string pgsqlConnection = ConfigurationManager.ConnectionStrings["pgsqlConnection"].ConnectionString.ToString();
/// <summary>
/// select查询
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static DataSet PostgreTable(string sql)
{
DataSet ds = new DataSet();
using (NpgsqlConnection conn = new NpgsqlConnection(pgsqlConnection))
{
conn.Open();
NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);
NpgsqlDataAdapter sda = new NpgsqlDataAdapter(cmd);
sda.Fill(ds);
}
return ds;
}
/// <summary>
/// 执行sql返回是否成功
/// </summary>
/// <param name="?"></param>
/// <returns></returns>
public static bool PostgreExecuQuery(string StrText)
{
bool bools = false;
using (NpgsqlConnection conn = new NpgsqlConnection(pgsqlConnection))
{
conn.Open();
NpgsqlCommand cmd = new NpgsqlCommand(StrText, conn);
int n = cmd.ExecuteNonQuery();
conn.Close();
bools = n > 0;
}
return bools;
}
/// <summary>
/// 执行sql返回字符
/// </summary>
/// <param name="strText"></param>
/// <param name="pgsqlConnection"></param>
/// <returns></returns>
public static string GetpostgreExecuteScalar(string strText)
{
using (NpgsqlConnection conn = new NpgsqlConnection(pgsqlConnection))
{
conn.Open();
NpgsqlCommand cmd = new NpgsqlCommand(strText, conn);
string PostgreScalar = cmd.ExecuteScalar().ToString();
if (PostgreScalar != null || !string.IsNullOrEmpty(PostgreScalar))
return PostgreScalar;
else return null;
}
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/myprojectgit/POSTSQLNET.git
git@gitee.com:myprojectgit/POSTSQLNET.git
myprojectgit
POSTSQLNET
POSTSQLNET
master

搜索帮助