asp net 操作数据库

12 篇文章 0 订阅
11 篇文章 0 订阅
  //定义
            String strConn, strSql;
            OleDbConnection myConn;
            OleDbCommand myComm;
            //连接数据库
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/test.mdb");
            myConn = new OleDbConnection(strConn);
            myConn.Open();
            //显示数据
            strSql = "select * from students order by ID asc";//sql语句
            myComm = new OleDbCommand(strSql, myConn);


            OleDbDataReader rs = myComm.ExecuteReader();
            
            List<StuModels> list = new List<StuModels>();
            StuModels usermodel;




            while (rs.Read())
            {
                usermodel = new StuModels();
                usermodel.id = Convert.ToInt32(rs["id"]);
                usermodel.Name = rs["Name"].ToString();
                usermodel.tel = rs["tel"].ToString();
                list.Add(usermodel);
            }
            


            ViewData["list"] = list;


            return View("Students");
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<html> <head> <title>分页例子</title> <!--以下是分页的样式,可以自己修改--> <style type="text/css"> .page_size_first_page{text-decoration:none;font-size:13px;color:black;} .page_size_prev_page{text-decoration:none;font-size:13px;color:black;} .page_size_next_page{text-decoration:none;font-size:13px;color:black;} .page_size_last_page{text-decoration:none;font-size:13px;color:black;} .page_size_current_page_text{font-size:13px;color:black;} .page_size_current_page_number{font-size:13px;color:red;} .page_size_page_count_text{font-size:13px;color:black;} .page_size_page_count_number{font-size:13px;color:red;} .page_size_rs_count_text{font-size:13px;color:black;} .page_size_rs_count_number{font-size:13px;color:red;} .page_size_page_size_text{font-size:13px;color:black;} .page_size_page_size_number{font-size:13px;color:red;} .page_size_text{font-size:13px;color:black;} </style> </head> <body> <% '获取地址栏传来的当前页码 dim current_page as string=request.querystring("current_page") '如果当前页码为空,默认页就是第1页 if(current_page="")then:current_page="1":end if dim dt as datatable=db.get_datatable("select * from zc_table",10,current_page) '以上是将sql语句得出的结果按10条每页来分页,并返回指定页的结果 dim temp_start as integer '由于dt里面只有当前页的结果,所以全部输出来就可以了 for temp_start=0 to dt.rows.count-1 %> <%=dt.rows(temp_start)("id")%><br/> <% next response.write(db.get_pagesize("index.aspx?dry_temp=0&zc_keyword=xxfaxy")) '请更改当前文件名 '如果不需要传递参数请人为的传递一个无效参数就好了 %> </body> </html> 这样就完成了分页 添加 删除 修改 查询数据一句代码就搞定,简单得你不敢相信。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值