笔记8:winfrom连接数据库DBHelp

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data; namespace 库存管理系统
{
class DBHelf
{
//增删改
public int sqlDS(String sql)
{
string Conn = "server=.;integrated security=true;database=GoodsManager";
SqlConnection sqlconn = new SqlConnection(Conn);
SqlCommand sqlcomm = new SqlCommand(sql, sqlconn); sqlconn.Open();
int i = sqlcomm.ExecuteNonQuery();
sqlconn.Close();
return i;
}
//查询
public DataTable sqlCha(string sql)
{
DataTable table = new DataTable();
string Conn = "server=.;integrated security=true;database=GoodsManager";
SqlConnection sqlconn = new SqlConnection(Conn);
SqlCommand sqlcomm = new SqlCommand(sql, sqlconn); SqlDataAdapter da = new SqlDataAdapter(sqlcomm);
da.Fill(table);
return table;
}
}
}
上一篇:JavaScript跨浏览器处理事件以及相关对象


下一篇:.Net下SQLite的DBHelp