当前位置: 首页>>代码示例>>C#>>正文


C# DB.DBconn方法代码示例

本文整理汇总了C#中DB.DBconn方法的典型用法代码示例。如果您正苦于以下问题:C# DB.DBconn方法的具体用法?C# DB.DBconn怎么用?C# DB.DBconn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB的用法示例。


在下文中一共展示了DB.DBconn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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();
                }
            }

       
    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:60,代码来源:finalresults_informationInput.aspx.cs

示例2: 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();
       }
    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:50,代码来源:passwordModify.aspx.cs

示例3: 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();
         }
     
    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:29,代码来源:Bulletin.aspx.cs

示例4: 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;

    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:29,代码来源:Parameter.cs

示例5: InsertDataToSQL

//向sql数据库表插入数据
    public bool InsertDataToSQL(string insert)
    { 
        DB db=new DB();
        SqlConnection conn = db.DBconn();//连接数据库
        //若数据库连接的当前状态是关闭的,则打开连接
      return db.Insert(insert,conn);
    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:8,代码来源:EXCELtoSQL.cs

示例6: 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);
 }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:8,代码来源:Default.aspx.cs

示例7: 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>");
        }

    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:56,代码来源:paperFileUp.aspx.cs

示例8: 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();
        }


    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:55,代码来源:collegeExamine.aspx.cs

示例9: 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();

        }
    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:54,代码来源:Test3.aspx.cs

示例10: 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>");
        }



    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:46,代码来源:studentSelect.aspx.cs

示例11: 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();
        }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:38,代码来源:Teacher.master.cs

示例12: 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>");

        }  

    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:25,代码来源:Default.aspx.cs

示例13: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {
        DB db = new DB();
        SqlConnection conn = db.DBconn();
        if (this.TextBox2.Text == "")
        {
            Response.Write("<script>alert('公告标题不可以为空,请重新发布。')</script>");
            return;

        }

        String insert = "insert into Bulletin(admin_ID,admin_Name,topic,content,time) values('" + Session["username"].ToString() + "','" + Session["name"].ToString() + "','" + this.TextBox2.Text + "','" + FreeTextBox1 .Text+ "','" + DateTime.Now + "') ";
        if (db.Insert(insert, conn))
        {
            Response.Write("<script>alert('公告发布成功。');location='issueBulletin.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('公告发布失败。可能超出公告最大字数4000字。');location='issueBulletin.aspx'</script>");
        }



    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:24,代码来源:issueBulletin.aspx.cs

示例14: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {   
        DB db=new DB();
    
  
        if (Button1.Text == "提交")//插入操作
        {
             //查找是否存在于表中如果存在则相当已修改,不存在为插入
          
            String insert = "insert into studentTask(Depart,specify,name,student_ID,class,period,periodUp,teacher_Name,title,kind,project_Name,project_Depart,project_Num,content,aim,ref,remark,Year,teacher_ID) values('" + Label1.Text + "','" + Label2.Text + "','" + Label3.Text + "','" + Label4.Text + "','" + Label5.Text + "','" + Label6.Text + "','" + Label7.Text + "','" + Label8.Text + "','" + Label9.Text + "','" + RadioButtonList1.SelectedValue + "','" + Label10.Text + "','" + Label11.Text + "','" + Label12.Text + "','" + this.TextBox1.Text + "','" + this.TextBox2.Text + "','" + this.TextBox3.Text + "','" + this.TextBox4.Text + "','" + Session["year"] + "','" + Session["teacher_ID"] + "') ";
         
           if(db.Insert(insert,db.DBconn())){
               Response.Write("<script>alert('学生任务书填写成功。');location='studentTaskPaper.aspx'</script>");
           }
            else{
                Response.Write("<script>alert('学生任务书填写失败。');location='studentTaskPaper.aspx'</script>");
            }
       
        }
        else//更新操作
        {
            

            String update = "update studentTask set content='"+this.TextBox1.Text+"',aim='"+this.TextBox2.Text+"',ref='"+this.TextBox3.Text+"',remark='"+this.TextBox4.Text+"' where student_ID='" + Session["username"] + "'";
            
            if (db.Insert(update, db.DBconn()))
            {
                Response.Write("<script>alert('学生任务书修改成功。');location='studentTaskPaper.aspx'</script>");
            }
            else
            {
                Response.Write("<script>alert('学生任务书修改失败。');location='studentTaskPaper.aspx'</script>");
            }
       
        }
    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:36,代码来源:studentTaskPaper.aspx.cs

示例15: select

    public void select(int PRI, int Select){
         DB db = new DB(); 
   
        //获取学生信息
        string student_ID = Session["username"].ToString();
        string name =  Session["name"].ToString();
        String sel = "select * from student where student_ID='" +student_ID+"'";
        DataSet ds = db.Select(sel,db.DBconn());
         String class1="";
         String grade = "";
        try
        {
         class1 = ds.Tables[0].Rows[0][13].ToString();
         grade = ds.Tables[0].Rows[0][15].ToString();
         ds.Clear();
        }
        catch
        {
            Response.Write("<script>alert('数据库出错,获取学生信息错误。');location='studentSelect.aspx'</script>");
        }

        //获取论文信息
      
        string teacher_ID=Request.QueryString["teacher_ID"];
          sel = "select * from paperApply where id='" +Session["paperid"]+ "'";
           ds = db.Select(sel, db.DBconn());
          String title = "";
          String teacher_Name = "";
          String direction = "";
          String introduce = "";
          String paperid = "";
          try
          {

               title =ds.Tables[0].Rows[0][3].ToString();
               teacher_Name = Convert.ToString(ds.Tables[0].Rows[0][20].ToString());
               direction = ds.Tables[0].Rows[0][4].ToString();
               introduce =ds.Tables[0].Rows[0][13].ToString();
               paperid=ds.Tables[0].Rows[0][0].ToString();
              ds.Clear();

          }
          catch
          {
              Response.Write("<script>alert('数据库出错,获取教师信息错误。');location='studentSelect.aspx'</script>");
          }

        int priority = PRI;
        Response.Write("<script>if(confirm('这将是您的第" + priority + "志愿,是否选定?选定后如需修改只能通过删除重选。')){ } else{location='Default.aspx'}</script>");
        string insert1 = "insert into themeSelectedResult(student_ID,name,class,teacher_ID,teacher_name,title,direction,introduce,priority,grade,paperid)  values('" + student_ID + "','" + name + "','" + class1 + "','" + teacher_ID + "','" + teacher_Name + "','" + title + "','" + direction + "','" + introduce + "','" + priority + "','" + grade + "','" + paperid + "')";//导入数据
        Select++;
        string update = "";
        if (priority == 1)
        {
             update = "update paperApply set first_select='" + Select + "' where id='" + paperid + "'";//更新选题情况信息
        }
        if (priority == 2)
        {
             update = "update paperApply set second_select='" + Select + "' where id='" + paperid + "'";//更新选题情况信息
        }
        if (priority == 3)
        {
            update = "update paperApply set third_select='" + Select + "' where id='" + paperid + "'";//更新选题情况信息
        }

        if (db.Insert(insert1, db.DBconn()) && db.Update(update, db.DBconn()))
        {
            Response.Write("<script>alert('您的课题第" + priority + "志愿选择成功');location='studentSelect.aspx'</script>");
        }

        else
        {
            Response.Write("<script>alert('您的课题第" + priority + "志愿选择失败');location='studentSelect.aspx'</script>");
        }
    }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:75,代码来源:studentSelect1.aspx.cs


注:本文中的DB.DBconn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。