把txt作为数据源绑定到GridView中
先在APP_Data文件夹下新建一个txt文件:(输入一些内容先,用逗号隔开)
对于txt作为数据的好处,我想了想:
1.文件小
2.添加字段容易
..............
应用场所:
1.在线人数统计;
2.IP统计;
...............
大家发表一下意见。继续添加功能。
id,nameee,test
1,01,ddd
2,xian,ff
3,陆,tff est
在页面拉一个GridView控件,Page_Load里写:1,01,ddd
2,xian,ff
3,陆,tff est
protected void Page_Load(object sender, EventArgs e)
{
string ConnectionString;
string SQLString;
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("./App_Data") + ";Extended Properties=\"Text;HDR=yes;FMT=Delimited\"";
SQLString = "Select * from data.txt";
OleDbConnection ConnectionText = new OleDbConnection();
ConnectionText.ConnectionString = ConnectionString;
ConnectionText.Open();
OleDbDataAdapter AdapterText = new OleDbDataAdapter(SQLString, ConnectionText);
DataSet DataSetText = new DataSet("TextFiles");
AdapterText.Fill(DataSetText, "TextFile");
GridView1.DataSource = DataSetText;
GridView1.DataBind();
ConnectionText.Close();
}
{
string ConnectionString;
string SQLString;
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("./App_Data") + ";Extended Properties=\"Text;HDR=yes;FMT=Delimited\"";
SQLString = "Select * from data.txt";
OleDbConnection ConnectionText = new OleDbConnection();
ConnectionText.ConnectionString = ConnectionString;
ConnectionText.Open();
OleDbDataAdapter AdapterText = new OleDbDataAdapter(SQLString, ConnectionText);
DataSet DataSetText = new DataSet("TextFiles");
AdapterText.Fill(DataSetText, "TextFile");
GridView1.DataSource = DataSetText;
GridView1.DataBind();
ConnectionText.Close();
}
对于txt作为数据的好处,我想了想:
1.文件小
2.添加字段容易
..............
应用场所:
1.在线人数统计;
2.IP统计;
...............
大家发表一下意见。继续添加功能。