App_Code/DataBase.cs
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.OleDb;//引入命名空间
using System.Data; //引入命名空间
using System.Data.SqlClient;
public class DataBase
{
public SqlConnection con;
//获取连接字符串
string connStr = "Data Source=.;Initial Catalog=Book;Integrated Security=True";
public void open()//打开数据库
{
con = new SqlConnection(connStr); // 设置连接字符串
con.Open();
}
public void close()//关闭数据库
{
con.Close();
con.Dispose();
}
public DataSet GetDataSet(string sqlStr)//查询数据库,得到数据集
{
open();
SqlDataAdapter sda = new SqlDataAdapter(sqlStr, con);
DataSet ds = new DataSet();
sda.Fill(ds);
close();
if (ds.Tables[0].Rows.Count != 0)
{
return ds; // 若找到相应的数据,则返回数据集
}
else
{
return null; // 若没有找到相应的数据,返回空值
}
}
public bool UpdateDB(string sqlStr)//更新数据库
{
open();
SqlCommand com = new SqlCommand(sqlStr, con);
com.ExecuteNonQuery();
// 设置Command对象的CommandType属性
com.CommandType = CommandType.Text;
try
{
int count = 0;
count = com.ExecuteNonQuery(); // 执行SQL语句
if (count != 0)
return true;
else
return false;
}
catch (Exception ex)
{
return false;
}
后面还有 12 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。