11-16查询Student中的所有学生记录,并在table中显示。
来源:互联网 发布:淘宝商城的推广 编辑:程序博客网 时间:2024/06/06 01:44
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 查询 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string constr = "Data Source=.;Initial Catalog=Schools;Persist Security Info=True;User ID=sa;Password=910809";
using (SqlConnection con = new SqlConnection(constr))
{
con.Open();
using (SqlCommand cmd = con.CreateCommand ())
{
string sql = "select * from Student";
cmd.CommandText = sql;
using (SqlDataReader reader=cmd.ExecuteReader ())
{
if(reader .HasRows)
{
while (reader .Read ())
{
TableRow trRow = new TableRow();//-------读取的是行
//获取第一条记录的第一列中的值
TableCell trCell = new TableCell();//-----读取的是列
trCell.BorderStyle = BorderStyle.Solid;
trCell.BorderWidth = 1;
trCell.Text = reader.GetValue(0).ToString();
trRow.Cells.Add(trCell );//_------把列添加到行中
//获取第一条记录的第二列中的值
trCell = new TableCell();
trCell.BorderStyle = BorderStyle.Solid;
trCell.BorderWidth = 1;
trCell.Text =reader.GetValue(1).ToString();
trRow.Cells.Add(trCell);
//获取第一条记录的第三列中的值
trCell = new TableCell();
trCell.BorderStyle = BorderStyle.Solid;
trCell.BorderWidth = 1;
trCell.Text = reader.GetValue(2).ToString();
trRow.Cells.Add(trCell);
//获取第一条记录的第四列中的值
trCell = new TableCell();
trCell.BorderStyle = BorderStyle.Solid;
trCell.BorderWidth = 1;
trCell.Text = reader.GetValue(3).ToString();
trRow.Cells.Add(trCell);
//获取第一条记录的第五列中的值
trCell = new TableCell();
trCell.BorderStyle = BorderStyle.Solid;
trCell.BorderWidth = 1;
trCell.Text = reader.GetValue(4).ToString();
trRow.Cells.Add(trCell);
Table1.Rows.Add(trRow );//----------把行添加到table中去
}
}
}
}
}
}
}
}
- 11-16查询Student中的所有学生记录,并在table中显示。
- 实现将student中的所有信息在一个模板页上显示,格式参考课件中的图片。并实现编辑功能
- 实现将student中的所有信息在一个模板页上显示,格式参考课件中的图片。并实现编辑功能。
- 如何在PL/SQL Developer中设置使其可以显示查询返回的所有记录?
- 如何在PL/SQL Developer中设置使其可以显示查询返回的所有记录
- 如何在PL/SQL Developer中显示查询返回的所有记录?
- 在PL/SQL Developer中怎样显示通过查询表返回的所有记录?
- 数据适配器对象和数据集对象(一般用来执行查询的动作,例如:查看表中的所有数据并显示在主窗体中)
- 查询并逐行显示数据库表中的所有字段名
- 查询第二学期的学生中所有在1990年后出生的学生姓名
- .写student类中的select,delete,update,insert方法并在objectDataSource中应用
- 利用数据库实现分页,并显示在Table中
- 计算增加到目的表中的记录数并显示在状态栏中
- SQL查询学生信息表中的学生记录
- Student类对学生成绩进行查询
- 一个项目:查询所有项目并显示
- Sql Server中写查询表存储过程,并在winfrom中的dataGridView控件中显示表内容
- 两个小技巧:vo查询所有记录数和adf中grid像table中一样自动添加行
- 验证码工具类
- TS流的解码过程-ES-PES-DTS-PTS-PCR
- android拍照
- MVC模式和总结
- 网络高清时代,点亮数字生活
- 11-16查询Student中的所有学生记录,并在table中显示。
- 利用function的参数特点,进行事件绑定
- ubuntu下编译android代码
- php中session机制探究
- Mac OS X系统快捷键一览表
- Linux 上DenyHosts阻止SSH暴力攻击
- ACTIVEX_MFC_属性持久化
- C++第12周项目4——用函数解决素数、回文数等
- 数据结构——竞选海报