DBMNG数据库管理与应用

才能是来自独创性。独创性是思维、观察、理解和判断的一种独特的方式。
当前位置:首页 > 服务器配置 > IIS&ASP

asp.net C# DBHelper类封装

01using System;
02using System.Collections.Generic;
03using System.Linq;
04using System.Text;
05using System.Threading.Tasks;
06using System.Data;
07using System.Data.SqlClient;
08 
09 
10namespace DAL
11{
12public class DBHelper
13{
14//创建链接字符串
15public static string sqlconn = "Data Source=.;Initial Catalog=StudentDB;Integrated Security=True";
16//创建链接对象
17public static SqlConnection conn = new SqlConnection(sqlconn);
18 
19//增删改方法
20public static bool ExeQuteNonQuery(string sql)
21{
22//打开链接对象
23conn.Open();
24//创建命令对象
25SqlCommand cmd = new SqlCommand(sql,conn);
26//执行命令对象
27int result = cmd.ExecuteNonQuery();
28conn.Close();
29if (result > 0)
30{
31return true;
32}
33else {
34return false;
35}
36}
37//查询方法
38public DataTable ExeQuteTable(string sql)
39{
40//创建数据适配器
41SqlDataAdapter da = new SqlDataAdapter(sql, conn);
42DataTable table=new DataTable ();
43da.Fill(table);
44return table;
45}
46 
47}
48}
本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2025 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号