📄 dbhelper.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public class DBhelper
{
//使用sa登陆方式
//private static string strCon = "server=.;database=SelectCourseTC;uid=sa;pwd=sa.;";
//使用windows验证登陆方式
private static string strCon = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=LibraryManager;Data Source=.";
public static UserInfo sqlUserInfo(string strSql)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = strCon;
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = strSql;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
UserInfo userinfo = null;
if (dr.Read())
{
userinfo = new UserInfo();
userinfo.UserID = dr.GetInt32(0);
userinfo.UserLoginID = dr.GetString(1);
userinfo.UserPwd = dr.GetString(2);
userinfo.UserName = dr.GetString(3);
userinfo.UserStatus = dr.GetInt32(4);
}
dr.Close();
con.Close();
return userinfo;
}
public static BookInfos sqlBookInfo(string strSql)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = strCon;
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = strSql;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
BookInfos bookInfos = null;
if (dr.Read())
{
bookInfos = new BookInfos();
bookInfos.BookID = dr.GetInt32(0);
bookInfos.BookName = dr.GetString(1);
bookInfos.BookWriter = dr.GetString(2);
bookInfos.BookFrom = dr.GetString(3);
bookInfos.BookContent = dr.GetString(4);
bookInfos.BookNum = dr.GetInt32(5);
bookInfos.BookSite = dr.GetString(6);
}
dr.Close();
con.Close();
return bookInfos;
}
public static BorrowInfos sqlBorrowInfo(string strSql)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = strCon;
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = strSql;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
BorrowInfos borrowInfos = null;
if (dr.Read())
{
borrowInfos = new BorrowInfos();
borrowInfos.BorrowID = dr.GetInt32(0);
borrowInfos.BookID = dr.GetInt32(1);
borrowInfos.UserID = dr.GetInt32(2);
borrowInfos.BorrowDate = dr.GetString(3);
borrowInfos.BackDate = dr.GetString(4);
borrowInfos.BorrowStatus = dr.GetInt32(5);
}
dr.Close();
con.Close();
return borrowInfos;
}
public static int sqlinit(string strSql)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = strCon;
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = strSql;
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
return i;
}
public static DataTable sqlLoad(string strSql)
{
SqlDataAdapter da = new SqlDataAdapter(strSql, strCon);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -