本文整理汇总了C#中DbHelper.ExecuteReader方法的典型用法代码示例。如果您正苦于以下问题:C# DbHelper.ExecuteReader方法的具体用法?C# DbHelper.ExecuteReader怎么用?C# DbHelper.ExecuteReader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbHelper
的用法示例。
在下文中一共展示了DbHelper.ExecuteReader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uname"] == null)
{
Response.Write("<script>alert('系统超时或非法登录,请重新登录!');window.location.href='default.aspx';</script>");
return;
}
if (Session["uid"]==null)
{
Response.Write("<script>alert('系统超时或非法登录,请重新登录!');window.location.href='default.aspx';</script>");
return;
}
if (Session["ucount"] == null)
{
Response.Write("<script>alert('系统超时或非法登录,请重新登录!');window.location.href='default.aspx';</script>");
return;
}
string uid = Session["uid"].ToString();
dbh = new DbHelper();
string sql;
sql = string.Format("select count(*) from userinfo where parent_id='{0}' ", uid);
DbCommand dbc = dbh.GetSqlStringCommond(sql);
int count=int.Parse(dbh.ExecuteScalar(dbc).ToString());
int usercount = int.Parse(Session["ucount"].ToString()); ;
if (count >= usercount)
{
Response.Write("<script>alert('用户最大数超出设定范围,请联系管理员!');window.location.href='userlist.aspx';</script>");
return;
}
if (Request["id"] != null)
{
id = Request["id"];
sql = string.Format("select * from userinfo where id='{0}' ", Request["id"]);
DbCommand dbc3 = dbh.GetSqlStringCommond(sql);
dbr = dbh.ExecuteReader(dbc3);
dbr.Read();
tb_guid.Text = dbr["guid"].ToString();
tb_memo.Text = dbr["memo"].ToString();
tb_buydate.Text = dbr["buy_date"].ToString();
tb_stopdate.Text = dbr["stop_date"].ToString();
tb_username.Text = dbr["user_name"].ToString();
rb_stop.Checked = dbr["active"].ToString() == "0" ? true : false;
rb_active.Checked = dbr["active"].ToString() == "0" ? false : true;
}
else
{
tb_guid.ReadOnly = false;
tb_buydate.Text = DateTime.Now.ToString("yyyyMMdd");
tb_stopdate.Text = DateTime.Now.AddYears(1).ToString("yyyyMMdd");
rb_stop.Checked = true;
}
}
示例2: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uname"] == null)
{
Response.Write("<script>alert('系统超时或非法登录,请重新登录!');window.location.href='default.aspx';</script>");
}
dbh = new DbHelper();
string sql;
sql = string.Format("select * from version" );
DbCommand dbc = dbh.GetSqlStringCommond(sql);
dbr = dbh.ExecuteReader(dbc);
this.GridView1.DataSource = dbr;
this.GridView1.DataBind();
}
示例3: GetCustomObjects
/// <summary>
/// 获取数据库中的所有自定义对象。
/// </summary>
/// <param name="databaseName">数据库名称</param>
/// <returns>自定义对象名称集合</returns>
public override IList<CustomObject> GetCustomObjects(string databaseName)
{
var result = new List<CustomObject>();
var dbUtil = new DbHelper(MYSQL_PROVIDER, string.Format(MYSQL_CONNECTION_FORMAT, this.ServerUri, this.Account, this.Password, databaseName));
var reader = dbUtil.ExecuteReader("show TABLES");
while (reader.Read())
{
result.Add(new CustomObject { Name = reader.GetString(0) });
}
return result;
}
示例4: GetDatabaseNames
/// <summary>
/// 获取数据库名称集合。
/// </summary>
/// <returns>数据库名称集合</returns>
public override IList<string> GetDatabaseNames()
{
var result = new List<string>();
var dbUtil = new DbHelper(MYSQL_PROVIDER, string.Format(MYSQL_CONNECTION_FORMAT, this.ServerUri, this.Account, this.Password, "mysql"));
var reader = dbUtil.ExecuteReader("show DATABASES");
while (reader.Read())
{
result.Add(reader.GetString(0));
}
return result;
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["uname"] == null)
{
Response.Write("<script>alert('系统超时或非法登录,请重新登录!');window.location.href='default.aspx';</script>");
return;
}
if (Request.Form["psw"] == null)
{
Response.Write("<script>alert('系统超时或非法登录,请重新登录!');window.location.href='default.aspx';</script>");
return;
}
DbHelper dbh = new DbHelper();
string user = Request.Form["uname"];
string psw = Request.Form["psw"];
string sql = "select count(*) as c from admin where [email protected] and [email protected]";
DbCommand cmd = dbh.GetSqlStringCommond(sql);
SqlParameter[] dbp = new SqlParameter[2];
dbp[0] = new SqlParameter();
dbp[0].ParameterName = "@u";
dbp[0].Value = user;
dbp[1] = new SqlParameter();
dbp[1].ParameterName = "@p";
dbp[1].Value = psw;
sql = dbh.ExecuteScalar(cmd, dbp).ToString();
if (sql != "1")
{
Response.Write("<script>alert('用户名密码错误,请重新输入!');window.location.href='default.aspx';</script>");
}
else
{
Session.Timeout = 30;
sql = "select * from admin where username='"+user+"' and password='"+psw +"'";
DbCommand cmd2 = dbh.GetSqlStringCommond(sql);
DbDataReader dr = dbh.ExecuteReader(cmd2);
dr.Read();
Session["uname"] = user;
Session["uid"] = dr["id"].ToString();
Session["ucount"] = dr["usercount"].ToString();
Response.Write("<script> window.location.href='userlist.aspx';</script>");
}
}
示例6: GetTableOrViewDetails
/// <summary>
/// 获取表或视图的详细信息。
/// </summary>
/// <param name="databaseName">数据库名称</param>
/// <param name="tableName">表或视图名称</param>
/// <param name="isView">是否为视图</param>
/// <returns>表或视图信息</returns>
public override DbTable GetTableOrViewDetails(string databaseName, string tableName, bool isView = false)
{
var result = new DbTable();
var dbUtil = new DbHelper(MYSQL_PROVIDER, string.Format(MYSQL_CONNECTION_FORMAT, this.ServerUri, this.Account, this.Password, databaseName));
result.Name = tableName;
result.ClassName = tableName.AsClassName();
result.Description = result.ClassName;
try
{
using (var reader = dbUtil.ExecuteReader(string.Format("DESC {0}", tableName)))
{
while (reader.Read())
{
var field = new DbColumn
{
Name = reader.GetString(0),
PropertyName = reader.GetString(0).PascalNaming(),
IsIdentity = !Convert.IsDBNull(reader[5]) && reader.GetString(5).Contains("auto_increment"),
IsPrimaryKey = !Convert.IsDBNull(reader[3]) && reader.GetString(3).ToUpper().Contains("PRI"),
Nullable = reader.GetString(2) == "YES",
Description = reader.GetString(0),
};
var sqlType = reader.GetString(1).Split(' ')[0];
if (sqlType.Contains('('))
{
sqlType = sqlType.Substring(0, sqlType.IndexOf('('));
}
field.SqlType = sqlType;
field.BasicType = sqlType;
result.Columns.Add(field);
}
}
}
catch { }
return result;
}