码迷,mamicode.com
首页 > 数据库 > 详细

笔记8:winfrom连接数据库DBHelp

时间:2016-04-18 22:34:25      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Data.Sql;
 6 using System.Data.SqlClient;
 7 using System.Data;
 8 
 9 namespace 库存管理系统
10 {
11     class DBHelf
12     {
13         //增删改
14         public int sqlDS(String sql)
15         {
16             string Conn = "server=.;integrated security=true;database=GoodsManager";
17             SqlConnection sqlconn = new SqlConnection(Conn);
18             SqlCommand sqlcomm = new SqlCommand(sql, sqlconn);
19 
20             sqlconn.Open();
21             int i = sqlcomm.ExecuteNonQuery();
22             sqlconn.Close();
23             return i;
24         }
25         //查询
26         public DataTable sqlCha(string sql)
27         {
28             DataTable table = new DataTable();
29             string Conn = "server=.;integrated security=true;database=GoodsManager";
30             SqlConnection sqlconn = new SqlConnection(Conn);
31             SqlCommand sqlcomm = new SqlCommand(sql, sqlconn);
32 
33             SqlDataAdapter da = new SqlDataAdapter(sqlcomm);
34             da.Fill(table);
35             return table;
36         }
37     }
38 }

 

笔记8:winfrom连接数据库DBHelp

标签:

原文地址:http://www.cnblogs.com/gx-143/p/5405967.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!