sqlite 转sql2005 出错
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.OleDb;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
/// <summary>
/// DB 的摘要说明
/// </summary>
public class DB
{
public DB()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 数据连接
/// </summary>
/// <returns></returns>
public static SqlConnection Getconn()//数据连接
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
// string conn = System.Configuration.ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
//return value;
if (conn.State.Equals(ConnectionState.Closed))
{
conn.Open();
}
return conn;
conn.Close();
}
/// <summary>
/// 获取单个用户信息
/// </summary>
/// <param name="NewsId"></param>
/// <returns></returns>
public SqlDataReader Getsing_User(int user_ID)//获取中文新闻版信息
{
SqlConnection Conn = Getconn();
SqlCommand Cmd = new SqlCommand("SELECT * FROM zp_User WHERE ( user_ID = " + user_ID.ToString() + ")", Conn);
Conn.Open();
return Cmd.ExecuteReader();
Conn.Close();
}
/// <summary>
/// 获取资讯信息
/// </summary>
/// <param name="NewsId"></param>
/// <returns></returns>
public SqlDataReader Getsing_index(int Id)//获取中文新闻版信息
{
SqlConnection Conn = Getconn();
SqlCommand Cmd = new SqlCommand("SELECT * FROM zp_News WHERE ( Id = " + Id.ToString() + ")", Conn);
Conn.Open();
return Cmd.ExecuteReader();
Conn.Close();
}
/// <summary>
/// 获取邮箱配置信息
/// </summary>
/// <param name="NewsId"></param>
/// <returns></returns>
public SqlDataReader Getsing_MailConfig(int Id)//获取中文新闻版信息
{
SqlConnection Conn = Getconn();
SqlCommand Cmd = new SqlCommand("SELECT * FROM zp_Mail_Config WHERE ( Id = " + Id.ToString() + ")", Conn);
Conn.Open();
return Cmd.ExecuteReader();
Conn.Close();
}
/// <summary>
/// 获取单条反馈信息
/// </summary>
/// <param name="NewsId"></param>
/// <returns></returns>
public SqlDataReader Getsing_Opinions(int Id)//获取单条反馈信息
{
SqlConnection Conn = Getconn();
SqlCommand Cmd = new SqlCommand("SELECT * FROM zp_Opinions WHERE ( Id = " + Id.ToString() + ")", Conn);
Conn.Open();
return Cmd.ExecuteReader();
Conn.Close();
}
/// <summary>
/// 获取关于我们信息
/// </summary>
/// <param name="NewsId"></param>
/// <returns></returns>
public SqlDataReader Getsing_About(int Id)//获取中文新闻版信息
{
SqlConnection Conn = Getconn();
SqlCommand Cmd = new SqlCommand("SELECT top (1) * FROM zp_About WHERE ( Id = " + Id.ToString() + ") ", Conn);
Conn.Open();
return Cmd.ExecuteReader();
Conn.Close();
}
/// <summary>
/// 获取人力资讯
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public SqlDataReader Getsing_Zhixun(int Id)//获取中文新闻版信息
{
SqlConnection Conn = Getconn();
SqlCommand Cmd = new SqlCommand("SELECT top (5) * FROM zp_News WHERE ( Id = " + Id.ToString() + ") ", Conn);
Conn.Open();
return Cmd.ExecuteReader();
Conn.Close();
}
/// <summary>
/// 获取LINK单条记录
/// </summary>
/// <param name="NewsId"></param>
/// <returns></returns>
public SqlDataReader Getsing_Link(int Id)//获取JOB单条文章
{
SqlConnection Conn = Getconn();
SqlCommand Cmd = new SqlCommand("SELECT * FROM zp_Link WHERE ( Id = " + Id.ToString() + ")", Conn);
Conn.Open();
// Conn.Close();
return Cmd.ExecuteReader();
Conn.Close();
//
}
一但读大量数据时就 会出现 应用池出错!!连接超时!!
还有就是我使用了两个类库连接数据库的!!! --------------------编程问答--------------------
--------------------编程问答--------------------
/// <summary>
/// 获取名企业图标
/// </summary>
/// <param name="NewsId"></param>
/// <returns></returns>
public SqlDataReader Getsing_Produst(int Id)//获取名企业图标
{
SqlConnection Conn = Getconn();
SqlCommand Cmd = new SqlCommand("SELECT TOP(1) * FROM zp_produst WHERE ( Id = " + Id.ToString() + ") ", Conn);
Conn.Open();
return Cmd.ExecuteReader();
Conn.Close();
}
/// <summary>
/// 获取中文版定单信息
/// </summary>
/// <param name="NewsId"></param>
/// <returns></returns>
public SqlDataReader Getsing_cn_Order(int Id)//获取中文版定单信息
{
SqlConnection Conn = Getconn();
SqlCommand Cmd = new SqlCommand("SELECT * FROM cn_Order WHERE ( Id = " + Id.ToString() + ") limit 1", Conn);
Conn.Open();
return Cmd.ExecuteReader();
Conn.Close();
}
/// <summary>
/// 获取英文版定单信息
/// </summary>
/// <param name="NewsId"></param>
/// <returns></returns>
public SqlDataReader Getsing_en_Order(int Id)//获取英文版定单信息
{
SqlConnection Conn = Getconn();
SqlCommand Cmd = new SqlCommand("SELECT * FROM en_Order WHERE ( Id = " + Id.ToString() + ") limit 1", Conn);
Conn.Open();
return Cmd.ExecuteReader();
Conn.Close();
}
/// <summary>
/// 获取配置信息
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public SqlDataReader Getsing_Config(int Id)//获取首页配置信息
{
SqlConnection Conn = Getconn();
SqlCommand Cmd = new SqlCommand("SELECT * FROM [Sum_config] WHERE ( [Id] = " + Id.ToString() + ")", Conn);
Conn.Open();
//Conn.Close();
return Cmd.ExecuteReader();
Conn.Close();
}
/// <summary>
/// 检测用户是否存在 用于登录
/// </summary>
/// <param name="XuenxiaoName"></param>
/// <returns></returns>
public bool CheckName2(string XuenxiaoName)
{
SqlConnection Conn = DB.Getconn();
SqlCommand Cmd = new SqlCommand("SELECT COUNT(*) FROM k_XuexiaoName WHERE ( XuexiaoName = '" + XuenxiaoName.ToString() + "')", Conn);
bool Flage = true;
int n = Convert.ToInt32(Cmd.ExecuteScalar()); //返回首行首列
Conn.Close();
if (n>0)
{
Flage = false;
}
return Flage;
}
/// <summary>
/// 获取!单个用户信息
/// </summary>
/// <param name="XuexiaoId"></param>
/// <returns></returns>
public SqlDataReader GetsingUser(string User_name,string User_mail)--------------------编程问答--------------------
{
SqlConnection Conn = Getconn();
string Get = "SELECT TOP (1) * FROM zp_user WHERE ( [user_Name] = '" + User_name.ToString() + "'and user_Email='" + User_mail.ToString() + "' ) ";
SqlCommand Cmd = new SqlCommand(Get, Conn);
return Cmd.ExecuteReader();
Conn.Close();
}
/// <summary>
/// 获取单个客户用户信息!
/// </summary>
/// <param name="XuexiaoId"></param>
/// <returns></returns>
public SqlDataReader GetsingKehu(int kehuid)
{
SqlConnection Conn = Getconn();
string Get = "SELECT * FROM [k900_kehu] WHERE ( [kehuid] = " + kehuid.ToString() + " ) limit 0,1";
SqlCommand Cmd = new SqlCommand(Get, Conn);
return Cmd.ExecuteReader();
Conn.Close();
}
/// <summary>
/// 团队伙伴用户登陆
/// </summary>
/// <param name="Name"></param>
/// <param name="Pwd"></param>
/// <returns></returns>
public SqlDataReader OfficeLonge(string Name, string Pwd)
{
SqlConnection Conn = Getconn();
string Long = "SELECT Officeid,is_no FROM k900_Office WHERE ( Name='" + Name.ToString() + "'" + " AND Pwd = " + "'" + Pwd.ToString() + "')";
SqlCommand UserCommand = new SqlCommand(Long, Conn);
SqlDataReader dr = null;
try
{
// Conn.Open();
dr = UserCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (OleDbException ex)
{
throw new Exception(ex.Message, ex);
}
return dr;
Conn.Close();
}
//=================================================
//功能描述:关闭数据库
//时间:2007.11.10
//=================================================
private static void closeConnection()
{
SqlConnection conn = DB.Getconn();
SqlCommand cmd = new SqlCommand();
if (conn.State == ConnectionState.Open)
{
conn.Close();
conn.Dispose();
cmd.Dispose();
}
}
//=================================================
//功能描述:执行SQL语句
//输入参数:sql,查询的SQL语句
//时间:2007.11.10
//=================================================
public static void execnonsql(string sql)
{
try
{
SqlConnection conn = DB.Getconn();
SqlCommand com = new SqlCommand(sql, conn);
com.ExecuteNonQuery();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}
//=================================================
//功能描述:获取DATASET
//输入参数:sql,查询的SQL语句
//返回值:DataSet
//时间:2007.11.10
//=================================================
public static DataSet getdataset(string sql)
{
try
{
SqlConnection conn = DB.Getconn();
SqlDataAdapter adp = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
adp.Fill(ds, "ds");
return ds;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}
//=================================================
//功能描述:获取DATASET1
//输入参数:sql,查询的SQL语句
//返回值:DataSet
//时间:2007.11.10
//=================================================
public static DataSet select(string sql,string tablename)
{
try
{
SqlConnection conn = DB.Getconn();
SqlDataAdapter adp = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
adp.Fill(ds, tablename);
return ds;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}
//=================================================
//功能描述:获取某个字段数据
//输入参数:sql,查询的SQL语句
//返回值:hang
//时间:2007.11.10
//=================================================
public static string FindString(string sql)
{
try
{
SqlConnection conn = DB.Getconn();
SqlCommand com = new SqlCommand(sql, conn);
string hang = Convert.ToString(com.ExecuteScalar());
return hang;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}
//=================================================
//功能描述:对DATAGRIG进行数据绑定,无排序
//输入参数:sql,查询的SQL语句;dg,需要绑定的DATAGRID控件
//返回值:无
//时间:2007.11.10
//=================================================
public static void binddatagrid(string sql, DataGrid dg)
{
try
{
DataSet ds = getdataset(sql);
dg.DataSource = ds.Tables[0].DefaultView;
dg.DataBind();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}
//=================================================
//功能描述:对DropDownList进行数据绑定,无排序
//输入参数:sql,查询的SQL语句;dg,需要绑定的DATAGRID控件
//返回值:无
//时间:2007.11.10
//=================================================
public static void bindDropDownList(string sql, DropDownList dl, string class_name, string id)
{
try
{
DataSet ds = getdataset(sql);
dl.DataSource = ds.Tables[0].DefaultView;
dl.DataTextField = class_name;
dl.DataValueField = id;
dl.DataBind();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}
//=================================================
//功能描述:对RadioButtonList进行数据绑定,无排序
//输入参数:sql,查询的SQL语句;dg,需要绑定的DATAGRID控件
//返回值:无
//时间:2007.11.10
//=================================================
public static void bindRadioButtonList(string sql, RadioButtonList rl, string class_name, string id)
{
try
{
DataSet ds = getdataset(sql);
rl.DataSource = ds.Tables[0].DefaultView;
rl.DataTextField = class_name;
rl.DataValueField = id;
rl.SelectedIndex = 0;
rl.DataBind();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}
//=================================================
//功能描述:对GridView进行数据绑定,无排序
//输入参数:sql,查询的SQL语句;dg,需要绑定的DATAGRID控件
//返回值:无
//时间:2007.11.10
//=================================================
public static void bindGridView(string sql, GridView dg)
{
try
{
SqlConnection conn = DB.Getconn();
DataSet ds = getdataset(sql);
dg.DataSource = ds.Tables[0].DefaultView;
dg.DataBind();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}
//=================================================
//功能描述:对datalist进行数据绑定,无排序
//输入参数:sql,查询的SQL语句;dl,需要绑定的datalist控件
//返回值:无
//时间:2007.11.10
//=================================================
public static void binddatalist(string sql, DataList dl)
{
try
{
SqlConnection conn = DB.Getconn();
DataSet ds = getdataset(sql);
dl.DataSource = ds.Tables[0].DefaultView;
dl.DataBind();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}
//=================================================
//功能描述:对repeater进行数据绑定,无排序
//输入参数:sql,查询的SQL语句;dl,需要绑定的repeater控件
//返回值:无
//时间:2007.11.10
//=================================================
public static void bindrepeater(string sql, Repeater rp)
{
try
{
SqlConnection conn = DB.Getconn();
DataSet ds = getdataset(sql);
rp.DataSource = ds.Tables[0].DefaultView;
rp.DataBind();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}
//=================================================
//功能描述:对listbox进行数据绑定
//输入参数:sql,查询的SQL语句;listb,需要绑定的listbox控件
//返回值:无
//时间:2007.11.10
//=================================================
public static void bindlistbox(string sql, ListBox listb, string class_name, string id)
{
try
{
SqlConnection conn = DB.Getconn();
DataSet ds = getdataset(sql);
listb.DataSource = ds.Tables[0].DefaultView;
listb.DataTextField = class_name;
listb.DataValueField = id;
listb.DataBind();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}
/// <summary>
/// 返回 HTML 字符串的编码结果
/// </summary>
/// <param name="str">字符串</param>
/// <returns>编码结果</returns>
public static string HtmlEncode(string str)
{
return HttpUtility.HtmlEncode(str);
}
/// <summary>
/// 返回 HTML 字符串的解码结果
/// </summary>
/// <param name="str">字符串</param>
/// <returns>解码结果</returns>
public static string HtmlDecode(string str)
{
return HttpUtility.HtmlDecode(str);
}
/// <summary>
/// 检测是否有Sql危险字符
/// </summary>
/// <param name="str">要判断字符串</param>
/// <returns>判断结果</returns>
public static bool IsSafeSqlString(string str)
{
return !Regex.IsMatch(str, @"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']");
}
/// <summary>
/// 管理员用户登陆
/// </summary>
/// <param name="UserName"></param>
/// <param name="UserPwd"></param>
/// <returns></returns>
public SqlDataReader AdminLonge(string DailiName, string Pwd)
{
SqlConnection Conn = Getconn();
string Long = "SELECT adminid FROM k900_admin WHERE ( adminUser='" + DailiName.ToString() + "'" + " AND adminpwd = " + "'" + Pwd.ToString() + "')";
SqlCommand UserCommand = new SqlCommand(Long, Conn);
SqlDataReader dr = null;
try
{
// Conn.Open();
dr = UserCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (OleDbException ex)
{
throw new Exception(ex.Message, ex);
}
return dr;
Conn.Close();
}
}
补充:.NET技术 , ASP.NET