从数据库读出数据然后以表格形式显示
来源:互联网 发布:淘宝历史成交价格 编辑:程序博客网 时间:2024/05/29 08:42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace demo3
{
public partial class SelectAll : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//1连接字符串
string constr = "data source=.;initial catalog=School;User ID=sa;Password=admin";
//2创建连接对象
using (SqlConnection con = new SqlConnection(constr))
{
//con.ConnectionString = constr;
//打开连接
//拼接sql语句
string sql = "select * from Student";
//3创建命令对象
using (SqlCommand cmd = new SqlCommand(sql, con))
{
//cmd.Connection = con;
//cmd.CommandText = sql;
con.Open();//
using (SqlDataReader reader = cmd.ExecuteReader())
//cmd.ExecuteReader(),调用ExecuteReader()这个方法,就执行了select * from Student。
{
if(reader.HasRows)//HasRows属性,可以判断这次查询有没有结果集返回。有为true,否则为false
{
while (reader.Read())
{
TableRow trRow = new TableRow();
//获取第一条记录的第一列中的值。
//reader.GetValue(0).ToString();
TableCell tcCell = new TableCell();
tcCell.BorderStyle = BorderStyle.Solid;
tcCell.BorderWidth = 1;
tcCell.Text = reader.GetValue(0).ToString();
trRow.Cells.Add(tcCell);
//获取第一条记录的第2列中的值。
tcCell = new TableCell();
tcCell.BorderStyle = BorderStyle.Solid;
tcCell.BorderWidth = 1;
tcCell.Text = reader.GetValue(1).ToString();
trRow.Cells.Add(tcCell);
//获取第一条记录的第3列中的值。
tcCell = new TableCell();
tcCell.BorderStyle = BorderStyle.Solid;
tcCell.BorderWidth = 1;
tcCell.Text = reader.GetValue(2).ToString();
trRow.Cells.Add(tcCell);
//获取第一条记录的第4列中的值。
tcCell = new TableCell();
tcCell.BorderStyle = BorderStyle.Solid;
tcCell.BorderWidth = 1;
tcCell.Text = reader.GetValue(3).ToString();
trRow.Cells.Add(tcCell);
//获取第一条记录的第5列中的值。
tcCell = new TableCell();
tcCell.BorderStyle = BorderStyle.Solid;
tcCell.BorderWidth = 1;
tcCell.Text = reader.GetValue(4).ToString();
trRow.Cells.Add(tcCell);
//获取第一条记录的第6列中的值。
tcCell = new TableCell();
tcCell.BorderStyle = BorderStyle.Solid;
tcCell.BorderWidth = 1;
tcCell.Text = reader.GetValue(5).ToString();
trRow.Cells.Add(tcCell);
Table1.Rows.Add(trRow);
}
}
// int t = cmd.ExecuteNonQuery();//执行insert,delete ,update正合适
//它的返回值就是执行命令后影响数据表中记录的条数。(正整数0---n)
//执行了 非insert,delete、update,返回值为-1
//this.Response.Write("查询了" + t + "行。");
}
}
}
}
}
}
- 从数据库读出数据然后以表格形式显示
- 图片以二进制形式存到数据库中,并从数据库中读出显示在页面上
- 如何把从数据库读出来的数据以excel格式显示到网页?
- 安卓开发前后台通信,从数据库中取数据并在前台以表格形式显示,以json格式传输
- struts2页面下载,从数据库把数据以excel表格形式导出
- 从数据库取出数据在jsp页面上以表格形式呈现,并对表格数据进行分页打印操作。
- 从数据库读出word然后IE打开
- java中查询数据库并以表格形式显示
- 以二进制码形式将图片存到数据库中,再从数据库中以二进制的形式从数据库中读出来
- 2014.12.04从数据库中查找数据,并以表格显示
- 如何将从数据库中的数据(表的形式显示出来的)导入到Excel表格中?
- 从数据库里读出数据,并将其按照下拉框的选择填入表格
- sdl从sdl_renderer读出数据,然后构造一个sdl_surface
- Fortran 以表格形式输出数据
- 用VB.NET 如果将任何文件以二进制形式保存在数据库,然后再从数据库读取出来
- 怎样在jsp页面上以表格的形式显示数据库里的内容
- 将数据库中的内容以表格形式显示到页面的div中
- 从数据库读出数据动态生成菜单栏
- 为什么需要htons(), ntohl(), ntohs(),htons() 函数 .模拟htonl、ntohl、htons、ntohs函数实现
- 整型和字符型的互相转化
- 解析 Linux 中的 VFS 文件系统机制(根文件系统的由来)
- AFNetworking 初探
- 白蛇传 冯梦龙 警世通言
- 从数据库读出数据然后以表格形式显示
- Java源码分析:深入探讨Iterator模式
- ADO.net复习题。填空。
- libjpeg解压损坏文件时的错误处理
- 【Linux入门学习之】Ubuntu常用软件
- VPS快速搭建LAMP(CentOS 6)
- 手动创建DataTable DataSet
- ubuntu安装配置Mysql
- ado.net用存储过程设计登录