日期:2014-05-17 浏览次数:20865 次
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt = CreateDataTable();
getDataTable(dt);
}
/// <summary>
/// 創建DataTable表
/// </summary>
/// <returns></returns>
private DataTable CreateDataTable()
{
DataTable dt = new DataTable("User");
dt.Columns.Add("user_name", typeof(string));
dt.Columns.Add("user_password", typeof(string));
dt.Columns.Add("user_page", typeof(int));
DataRow dr = dt.NewRow();
dr[0] = "zhangsan";
dr[1] = "123456";
dr[2] = 25;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "lisi";
dr[1] = "123";
dr[2] = 37;
dt.Rows.Add(dr);
return dt;
}
/// <summary>
/// 獲取DataTable中所有的值
/// </summary>
/// <param name="dt"></param>
private void getDataTable(DataTable dt)
{
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{