datatable与dataset加二维数组实现
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.OleDb;
public partial class reader : System.Web.UI.Page
{
const string connStr = "data source=127.0.0.1;user id=sa;password=***;initial catalog=***";
SqlConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
conn = new SqlConnection(connStr);
string sql = "select * from t_type";
SqlCommand cmd;
cmd = conn.CreateCommand();
cmd.CommandText = sql;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();//这个是为了循环的
DataTable dataTable = new DataTable();
dataTable.Load(reader);
string[,] rdrString = new string[dataTable.Rows.Count, 2];
for (int i = 0; i < dataTable.Rows.Count; i++)
{
for (int j = 0; j < 2; j++)
{
rdrString = dataTable.Rows[j].ToString();
}
}
reader.Close();
foreach (string temp in rdrString)
{
this.Label1.Text += temp + "<br>";
}
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.OleDb;
public partial class reader : System.Web.UI.Page
{
const string connStr = "data source=127.0.0.1;user id=sa;password=***;initial catalog=***";
SqlConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
conn = new SqlConnection(connStr);
string sql = "select * from t_type";
SqlCommand cmd;
cmd = conn.CreateCommand();
cmd.CommandText = sql;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();//这个是为了循环的
DataTable dataTable = new DataTable();
dataTable.Load(reader);
string[,] rdrString = new string[dataTable.Rows.Count, 2];
for (int i = 0; i < dataTable.Rows.Count; i++)
{
for (int j = 0; j < 2; j++)
{
rdrString
}
}
reader.Close();
foreach (string temp in rdrString)
{
this.Label1.Text += temp + "<br>";
}
}
}