本文整理汇总了C#中DB.Select方法的典型用法代码示例。如果您正苦于以下问题:C# DB.Select方法的具体用法?C# DB.Select怎么用?C# DB.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
DB db=new DB ();
string id = Request.QueryString["id"].ToString();
string sel="select * from Bulletin where id='"+Request.QueryString["id"]+"'";
DataSet ds = db.Select(sel, db.DBconn());
try
{
string admin_Name = ds.Tables[0].Rows[0][2].ToString();
string topic = ds.Tables[0].Rows[0][3].ToString();
DateTime time = Convert.ToDateTime(ds.Tables[0].Rows[0][5].ToString());
content = ds.Tables[0].Rows[0][4].ToString();
Label1.Text = topic;
Label2.Text = admin_Name;
Label3.Text = time.ToLongDateString();
Session["content"] = content;
}
catch
{
Response.Write("<script>alert('公告数据库错误。')</script>");
}
finally
{
ds.Clear();
}
}
示例2: DataTableToDB
protected void DataTableToDB(string _strExcelFileName)//插入操作
{
EXCELtoSQL ets = new EXCELtoSQL();
DataTable dtExcel = ets.ExcelToDataTable(_strExcelFileName, "Sheet1");
for (int i = 0; i < dtExcel.Rows.Count; i++)//按行读取
{
//在导入数据库操作之前需要验证数据库与之是否匹配
string info = "select * from paperApply where id='" + dtExcel.Rows[i][5].ToString() + "'";
DB db=new DB();
DataSet ds = db.Select(info, db.DBconn());
try
{
string title=ds.Tables[0].Rows[0][3].ToString();
string kind=ds.Tables[0].Rows[0][4].ToString();
string teacher_ID = ds.Tables[0].Rows[0][1].ToString();
string teacher_Name = ds.Tables[0].Rows[0][20].ToString();
if (title.Equals(dtExcel.Rows[i][6].ToString()) && kind.Equals(dtExcel.Rows[i][7].ToString()) && teacher_ID.Equals(dtExcel.Rows[i][3].ToString()) && teacher_Name.Equals(dtExcel.Rows[i][4].ToString()))
{
}else{//验证不通过
for (int j= 0; j<i; j++)//按行读取
{
string del="delete from select_Result where student_ID='"+dtExcel.Rows[i][1].ToString()+"'";
db.Delete(del,db.DBconn());
}//将已经插入的数据删除掉
Response.Write("<script language='javascript'>alert('读取的Excel数据中教师" + dtExcel.Rows[i][3].ToString() + dtExcel.Rows[i][4].ToString().Trim() + "所出的论文编号为" + dtExcel.Rows[i][5].ToString() + "的论文题目为" + dtExcel.Rows[i][6].ToString() + ",性质为" + dtExcel.Rows[i][7].ToString() + "的数据与数据库中的数据不一致,导入失败!(在数据库中教师" + teacher_ID + teacher_Name.Trim() + "出的该编号的题目:" + title + ",性质为" + kind + ")');location='finalresults_informationInput.aspx'</script>");
break;
}
// Response.Write("<script language='javascript'>alert('读取的数据为" + dtExcel.Rows[i][0].ToString() + "');</script>");
string insert = "insert into select_Result(class,student_ID,student_Name,teacher_ID,teacher_Name,title,grade,paperid,kind) values('" + dtExcel.Rows[i][0].ToString() +
"','" + dtExcel.Rows[i][1].ToString() + "','" + dtExcel.Rows[i][2].ToString().Trim() + "','" + dtExcel.Rows[i][3].ToString() +
"','" + dtExcel.Rows[i][4].ToString() + "','" + dtExcel.Rows[i][6].ToString() + "','" + dtExcel.Rows[i][8].ToString() + "','" + dtExcel.Rows[i][5].ToString() + "','" + dtExcel.Rows[i][7].ToString() + "')";
bool result = ets.InsertDataToSQL(insert);
if (result)
{
this.Label2.Text = "导入数据库成功!";
this.GridView1.Visible = false;
}
else
{
this.Label2.Text = "导入数据库失败!可能学号字段重复。";
}
Panel2.Visible = false;
this.Label2.Visible = true;
}
catch
{
Response.Write("<script language='javascript'>alert('读取数据库失败。');</script>");
}
finally
{
ds.Clear();
}
}
}
示例3: year
public int year(string student_ID)
{
//
//获取学生毕业学年
//
DB db = new DB();
string selec = "select * from student where student_ID='" + student_ID + "'";
DataSet ds = db.Select(selec, db.DBconn());
int year;
try
{
//如果读取到数据并装载数据
string grade = ds.Tables[0].Rows[0][15].ToString();
year = Convert.ToInt32(grade) + 4;
}
catch
{
year = DateTime.Now.Year;
}
finally
{
ds.Clear();
}
return year;
}
示例4: Button2_Click
protected void Button2_Click(object sender, EventArgs e)
{
string str = "select * from student where student_ID='20051308025'";
DB db = new DB();
DataSet ds = db.Select(str, db.DBconn());
SQLToWord sw = new SQLToWord();
sw.ExportToWord(ds);
}
示例5: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
string student_Name = "";
String student_ID ="";
try
{
student_Name = this.DropDownList1.SelectedItem.Text;
student_ID = this.DropDownList1.SelectedValue;
}
catch
{
Response.Write("<script language='javascript'>alert('请先选择您的学生!');location='paperFileUp.aspx'</script>");
}
string fullfilename = FileUpload1.PostedFile.FileName;
string filename = fullfilename.Substring(fullfilename.LastIndexOf("\\") + 1);
string type = fullfilename.Substring(fullfilename.LastIndexOf(".") + 1);
if (type == "doc" || type == "docx")
{
String title ="";
DB db= new DB();
String sel = "select * from select_Result where student_ID='" + student_ID + "'";
DataSet ds = db.Select(sel, db.DBconn());
try
{
title = ds.Tables[0].Rows[0][6].ToString();
}
catch
{
Response.Write("<script language='javascript'>alert('读取论文数据错误!');location='paperFileUp.aspx'</script>");
}
finally
{
ds.Clear();
}
String fileName = student_ID + student_Name+title+"."+type;
Response.Write("<script>if(confirm('您上传的文件名为" + filename + ",文件大小为"+this.FileUpload1. PostedFile.ContentLength+"B,是否上传?')){ } else{location='paperFileUp.aspx'}</script>");
//上传
this.FileUpload1.PostedFile.SaveAs(Server.MapPath("../论文上传/") + fileName);
// Label1.Text = "上传成功!文件路径为" + fullfilename + "文件名称为:" + filename + "文件格式为" + type + "文件限定名称和大小为" + this.FileUpload1.PostedFile.FileName + this.FileUpload1.PostedFile.ContentLength;
this.Label1.Text = "上传成功!";
}
else
{
Response.Write("<script language='javascript'>alert('你选择的文件格式不正确!');location='paperFileUp.aspx'</script>");
}
}
示例6: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null)
{
Response.Write("<script>alert('用户登录超时,请重新登录。');location='../Default.aspx'</script>");
return;
}
if (!Page.IsPostBack)
{
this.GridView1.Visible = false;
this.GridView2.Visible = true;
}
DB db = new DB();
string role = Session["role"].ToString();
if (role == "院领导")//权限判定
{
}
else
{
Response.Write("<script language='javascript'>alert('你的角色为" + role + ",不可以进入院领导审核页面!');location='Default.aspx'</script>");
}
String time = "select * from time where period='院审核'";
DataSet ds = db.Select(time, db.DBconn());
try
{
DateTime period_star1 = Convert.ToDateTime(ds.Tables[0].Rows[0][2].ToString().Trim()); //开始时间
DateTime period_end1 = Convert.ToDateTime(ds.Tables[0].Rows[0][3].ToString().Trim());//结束时间
String flg = ds.Tables[0].Rows[0][5].ToString().Trim(); ;//结束时间
DateTime now = DateTime.Today;
if (flg == "开" && (now >= period_star1) && (now <= period_end1))
{
}
else
{
Response.Write("<script>alert('对不起,该功能暂未开放。请关注系统公告。');location='Default.aspx'</script>");
}
}
catch
{
Response.Write("<script>alert('数据库时间设定取出过程错误。');location='Default.aspx'</script>");
}
finally
{
ds.Clear();
}
}
示例7: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
SQLtoWord SW = new SQLtoWord();
string str = "select student_ID,name,specialty from student where student_ID='20051308025'";
DB db = new DB();
DataSet ds = db.Select(str, db.DBconn());
try
{
string tex = ds.Tables[0].Rows[0][1].ToString();
string path1 = Server.MapPath(@"1.doc");
string path2 = Server.MapPath("file") + "\\" + "接收毕业生情况表" + ".doc";
string[] obDD = new string[3];
obDD[0] = "t1";
obDD[1] = "t2";
obDD[2] = "t3";
if (SW.ExportToWord(ds, path1, path2, obDD))
{
// Response.Write("<script>alert('文档写入成功!')<script>");
//yi流的方式传送给客户端
String filepath =path2;
System.IO.FileInfo file = new System.IO.FileInfo(filepath);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", file.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(file.FullName);
// 停止页面的执行
Response.End();
}
else
{
Response.Write("<script>alert('向word文件中写入数据出错.')<script>");
}
}
catch
{
Response.Write("<script>alert('数据库出错.')<script>");
}
finally
{
ds.Clear();
}
}
示例8: change_Click
protected void change_Click(object sender, EventArgs e)
{
DB db = new DB();
DataSet ds = db.Select("select * from admin where admin_ID='" + Session["username"] + "'", db.DBconn());
try
{ string password = ds.Tables[0].Rows[0][2].ToString();
md5Manger md5 = new md5Manger();
password = md5.Md5Decrypt(password);
//解密
string oldpassword = this.oldpassword.Text.Trim();
string newpassword = this.newpassword.Text.Trim();
if (password.Equals(oldpassword))
{
newpassword = md5.Md5Encrypt(newpassword);//加密
string updatepassword = "UPDATE admin SET password ='" + newpassword + "' WHERE admin_ID ='" + Session["username"].ToString() + "'";
bool result = db.Update(updatepassword, db.DBconn());
// Response.Write("<script language='javascript'>alert('您的jieguo为:" + result + "')</script>");
if (result)
{
this.message.Text = "密码更改成功!";
}
else
{
this.message.Text = "数据库更新失败!";
}
}
else
{
this.message.Text = "对不起,您的密码输入错误,请重新输入";
}
}
catch
{
Response.Write("<script>alert('数据库获取用户密码错误。');location='Default.aspx'</script>");
}
finally
{
ds.Clear();
}
}
示例9: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null)
{
Response.Write("<script>alert('用户登录超时,请重新登录。');location='../Default.aspx'</script>");
return;
}
if (!Page.IsPostBack)
{
this.GridView2.Visible = false;
this.GridView3.Visible = true;
}
DB db = new DB();
String time = "select * from time where period='学生选课'";
DataSet ds = db.Select(time, db.DBconn());
try
{
DateTime period_star1 = Convert.ToDateTime(ds.Tables[0].Rows[0][2].ToString()); //开始时间
DateTime period_end1 = Convert.ToDateTime(ds.Tables[0].Rows[0][3].ToString());//结束时间
String flg = ds.Tables[0].Rows[0][5].ToString(); ;//结束时间
ds.Clear();
DateTime now = DateTime.Today;
if (flg == "开" && (now>= period_star1) && (now <= period_end1))
{
this.Panel1.Visible = true;
this.Panel2.Visible = true;
this.Panel3.Visible = false;
}
else
{
this.Panel1.Visible = false;
this.Panel2.Visible = false;
this.Panel3.Visible = true;
}
}
catch
{
Response.Write("<script>alert('数据库时间设定取出过程错误,您可能还未设定时间。');location='Default.aspx'</script>");
}
}
示例10: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (null== Session["username"])
{
Response.Write("<script>alert('用户登录超时,请重新登录。');location='~/Default.aspx'</script>");
return;
}
DB db = new DB();
string role = Session["role"].ToString();
if (role == "教师" || role == "系领导" || role == "院领导")
{
}
else
{
Response.Write("<script language='javascript'>alert('你的角色为" + role + ",不可以进入教师页面!');location='../Default.aspx'</script>");
Response.Redirect("../Default.aspx");
}
// conn.Close();
//获取毕业年
String time1 = "select * from time where period='提交论文时间'";
DataSet ds=db.Select(time1,db.DBconn());
try{
DateTime period_star = Convert.ToDateTime(ds.Tables[0].Rows[0][2].ToString());
DateTime period_end = Convert.ToDateTime(ds.Tables[0].Rows[0][3].ToString());
int year = period_end.Year;//获取时间
Session["year"] = year;
Session["year1"] = year-4;
}catch{
Response.Write("<script language='javascript'>alert('获取学生的毕业学年错误。');location='../Default.aspx'</script>");
}finally{
}
ds.Clear();
}
示例11: judge
//判断用户是否存在,并转入相关的页面
public void judge(String str, string role)
{
//创建session对象
DB db = new DB();
DataSet ds = db.Select(str, db.DBconn());
try{
Session["username"] = ds.Tables[0].Rows[0][1].ToString();
Session["name"] = ds.Tables[0].Rows[0][2].ToString();
Session["role"] = ds.Tables[0].Rows[0][3].ToString();
// Session["flag"] = "Y";//用来标识用户登录成gong 和不超时
switch (role)
{
case "学生": Response.Redirect("student/Default.aspx"); break;//跳转到主页
case "教师": Response.Redirect("teacher/Default.aspx"); break;//跳转到主页
case "管理员": Response.Redirect("admin/Default.aspx"); break;//跳转到主页
}
}
catch
{
Response.Write("<script>alert('登录失败!请返回查找错误,请在用户名和密码正确的前提下选择正确的登录角色。');location='Default.aspx'</script>");
}
}
示例12: Get_Product_Price
private void Get_Product_Price()
{
try
{
DB d = new DB();
d.AddCondition("trd_pro_id", ((DataRowView)Product_CB.SelectedItem)[0]);
object price = d.Select(@"SELECT COALESCE(trd_price,0) FROM transactions_details JOIN transactions ON trd_trs_id=trs_id
WHERE trs_trn_id =1 AND trd_pro_id [email protected]_pro_id AND trs_date = (
SELECT MAX(trs_date) FROM transactions join transactions_details ON trd_trs_id=trs_id
WHERE trs_trn_id =1 AND trd_pro_id [email protected]_pro_id)");
Price_TB.Text = price == null ? "0.00" : price.ToString();
}
catch
{
}
}
示例13: Get_New_No
private void Get_New_No()
{
string No = "";
try
{
DB d = new DB();
d.AddCondition("Month", Date_DTP.Value.Value.Month);
d.AddCondition("Year", Date_DTP.Value.Value.Year);
No = d.Select("select Max(trs_no) from transactions where Month(trs_date)[email protected] and Year(trs_date)[email protected] ").ToString();
No_TB.Text = No == "" ? Date_DTP.Value.Value.ToString("yyMM") + "0001" : (int.Parse(No) + 1).ToString();
}
catch
{
}
}
示例14: Button2_Click
protected void Button2_Click(object sender, EventArgs e)
{
Button2.Enabled = false;
SQLtoWord SW = new SQLtoWord();
//string str = "select student_ID,name,Depart,specify,teacher_Name,title,AimandSense,state,content,schedule,ref from STReport where student_ID='" +Session["student_ID"].ToString().Trim()+ "'";
string str = " SELECT student_ID, name, Depart, specify, teacher_Name, title, AimandSense, state, content, schedule, ref FROM STReport WHERE (student_ID ='" + Session["student_ID"].ToString().Trim() + "')";
DB db = new DB();
DataSet ds = db.Select(str, db.DBconn());
try
{
string tex = ds.Tables[0].Rows[0][0].ToString();//ceshi
string path1 = Server.MapPath(@"..\\过程文档\\文档模版\\开题报告.doc");
string path2 = Server.MapPath(@"..\\过程文档\\开题报告") + "\\" + Session["student_ID"] + Session["student_Name"] + "开题报告.doc";
string[] obDD = new string[11];
obDD[0] = "student_ID";
obDD[1] = "name";
obDD[2] = "Depart";
obDD[3] = "specify";
obDD[4] = "teacher_Name";
obDD[5] = "title";
obDD[6] = "AimandSense";
obDD[7] = "state";
obDD[8] = "content";
obDD[9] = "schedule";
obDD[10] = "ref";
if (SW.ExportToWord(ds, path1, path2, obDD))
{
// Response.Write("<script>alert('文档写入成功!')<script>");
//yi流的方式传送给客户端
String filepath = path2;
System.IO.FileInfo file = new System.IO.FileInfo(filepath);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", file.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(file.FullName);
// 停止页面的执行
Response.End();
}
else
{
Response.Write("<script>alert('向word文件中写入数据出错.')</script>");
return;
}
}
catch
{
Response.Write("<script>alert('数据库出错,该同学可能还未填写开题报告.')</script>");
return;
}
finally
{
ds.Clear();
Button2.Enabled = true;
}
}
示例15: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
DB db=new DB();
//首先判断教师中期中数据
string sel="select * from midCheckForTea where teacher_ID='"+Session["username"]+"'";
DataSet ds=db.Select(sel,db.DBconn());
if(ds.Tables[0].Rows.Count>0){//有数据则更新操作
string update="update midCheckForTea set IsOne='"+this.RadioButtonList1.SelectedValue+"',IsTaskGive='"+this.RadioButtonList2.SelectedValue+"',IsrefRead='"+this.RadioButtonList3.SelectedValue+"',IsGuided='"+this.RadioButtonList4.SelectedValue+"',totalsituation='"+this.RadioButtonList5.SelectedValue+"',QA='"+this.TextBox1.Text+"' where teacher_ID='"+Session["username"]+"'";
if (!db.Update(update, db.DBconn()))
{
Response.Write("<script>alert('中期检查教师表修改失败。');location='midCheckEA.aspx'</script>");
}
}else{//无数据则进行插入
String insert="insert into midCheckForTea(teacher_ID,teacher_Name,Depart,specify,time,guiNum,IsOne,IsTaskGive,IsrefRead,IsGuided,totalsituation,QA,year) values('"+Session["username"]+ "','" + Label4.Text + "','" + Label1.Text+ "','" + Label2.Text + "','" + Label3.Text+ "','" + Label5.Text + "','" +this.RadioButtonList1.SelectedValue + "','" +this.RadioButtonList2.SelectedValue + "','" + this.RadioButtonList3.SelectedValue + "','" +this.RadioButtonList4.SelectedValue + "','" +this.RadioButtonList5.SelectedValue + "','" +this.TextBox1.Text + "','" +Session["year"] +"')";
if (!db.Insert(insert, db.DBconn()))
{
Response.Write("<script>alert('中期检查教师表填写失败。');location='midCheckEA.aspx'</script>");
}
}
ds.Clear();
//按照学生情况进行操作***********************************************************************
if (Button1.Text == "提交")//插入操作
{
//查找是否存在于表中如果存在则相当已修改,不存在为插入
string kind=this.RadioButtonList6.SelectedValue;
if(this.RadioButtonList6.SelectedValue.Equals("其他")&&this.TextBox2.Visible)
{
kind = this.TextBox2.Text;
}
String insert = "insert into midCheckForStu(teacher_ID,student_ID,student_Name,paperid,title,kind,Ischanged,IsReq,IsCom,Attitude,quality,result,state) values('" + Session["username"] + "','" + Session["student_ID"] + "','" + Label6.Text + "','" + Session["paperid"] + "','" + Label8.Text + "','" +kind + "','" +RadioButtonList7.SelectedValue + "','" + RadioButtonList8.SelectedValue + "','" + RadioButtonList9.SelectedValue + "','" + RadioButtonList10.SelectedValue + "','" +RadioButtonList11.SelectedValue + "','" + RadioButtonList12.SelectedValue +"','"+"已填写" + "') ";
if(db.Insert(insert,db.DBconn())){
Response.Write("<script>alert('中期检查填写成功。');location='midCheckEA.aspx'</script>");
}
else{
Response.Write("<script>alert('中期检查填写失败。');location='midCheckEA.aspx'</script>");
}
}
else//更新操作
{
string kind=this.RadioButtonList6.SelectedValue;
if(this.RadioButtonList6.SelectedValue.Equals("其他")&&this.TextBox2.Visible)
{
kind=this.TextBox2.Text;
}
String update = "update midCheckForStu set kind='" + kind + "',Ischanged='" + this.RadioButtonList7.SelectedValue + "',IsReq='" + this.RadioButtonList8.SelectedValue + "',IsCom='" + this.RadioButtonList9.SelectedValue + "',Attitude='" + this.RadioButtonList10.SelectedValue + "',quality='" + this.RadioButtonList11.SelectedValue + "',result='" + this.RadioButtonList12.SelectedValue + "' where student_ID='" + Session["student_ID"].ToString().Trim() + "'";
if (db.Update(update, db.DBconn()))
{
Response.Write("<script>alert('中期检查更新成功。');location='midCheckEA.aspx'</script>");
}
else
{
Response.Write("<script>alert('中期检查更新失败。');location='midCheckEA.aspx'</script>");
}
}
}