📄 dbconn.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;
using System.Data.OleDb;
/// <summary>
/// Summary description for DbConn
/// </summary>
public class DbConn
{
//private data members for providing the data objects to the caller
private string constr = "";
private System.Data.DataSet ds;
private SqlDataAdapter da;
private SqlConnection conn;
private SqlDataReader dr;
private SqlCommand com;
public DbConn()
{
try
{
constr = ConfigurationSettings.AppSettings.Get("constr");
//constr = constr1;
ds = new DataSet();
}
catch (Exception e1)
{
}
}
public string GetNewUserId()
{
try
{
string qry = "select max(Uid) from Registration";
conn = new SqlConnection();
com = new SqlCommand();
conn.ConnectionString = constr;
conn.Open();
com.CommandText = qry;
com.Connection = conn;
dr = com.ExecuteReader();
string newid = "1";
if (dr.Read())
{
newid = dr.GetValue(0).ToString();
if (newid.Equals(""))
{
newid = "1";
}
else
{
int t = (Int16.Parse(newid) + 1);
newid = t.ToString();
}
}
conn.Close();
return newid;
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
}
public bool Isvalidusername(string un)
{
bool f = true;
try
{
string qry = "select username from newuser where username='"+un+"'";
conn = new SqlConnection();
com = new SqlCommand();
conn.ConnectionString = constr;
conn.Open();
com.CommandText = qry;
com.Connection = conn;
dr = com.ExecuteReader();
if (dr.Read())
{
if (dr.IsDBNull(0))
{
f = false;
}
}
conn.Close();
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
return f;
}
public DataSet GetDataSet(string query)
{
try
{
da = new SqlDataAdapter(query, constr);
da.Fill(ds, "MyTable1");
}
catch (Exception e1)
{
}
if (ds.Tables.Count > 0)
return ds;
else
return null;
}
public SqlDataReader GetData(string qry)
{
conn = new SqlConnection();
com = new SqlCommand();
conn.ConnectionString = constr;
conn.Open();
com.CommandText = qry;
com.Connection = conn;
dr = com.ExecuteReader();
return dr;
}
public void StoreData(string qry)
{
try
{
conn = new SqlConnection();
com = new SqlCommand();
conn.ConnectionString = constr;
conn.Open();
com.CommandText = qry;
com.Connection = conn;
com.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -