[英]Data table in C#.net
I have a problem related to DataTable in .net. 我在.net中遇到与DataTable相关的问题。 i am trying to fill datatable on page_load .that part is ok no issue datatable correctly filled up with data.
我正在尝试在page_load上填充数据表。这部分是正常的没有问题数据表正确填充数据。 but I noticed that when I clicked button on page... it again try to fill datatable which just a time-consuming task... I want datatable should fill once only ,when , when site open in browser .. not at every click ... because I have a large amount of data in table so it takes time to load in datatable.. plz help me out ... here is my code:
但是我注意到当我点击页面上的按钮时...它再次尝试填充数据表,这只是一个耗时的任务......我希望数据表只应该填充一次,何时,当浏览器中的网站打开时......不是每次点击...因为我在表中有大量数据所以加载数据表需要时间.. plz帮助我...这是我的代码:
protectd void Page_Load(object sender, EventArgs e)
{
cnn.ConnectionString= ConfigurationManager.ConnectionStrings["con"].ConnectionString;
// if (this.IsPostBack == true)
{
dr1 = TableUtoP();
dtWordsList.Load(dr1);
}
}
OleDbDataReader TableUtoPunj(String ArrWord)
{
if (cnn.State == ConnectionState.Open)
{
cnn.Close();
}
cnn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "SELECT U, P from UtoP";
cmd.Connection = cnn;
OleDbDataReader dr = cmd.ExecuteReader();
return dr;
}
You need to check if the page is posting back or not, like this: 您需要检查页面是否回发,如下所示:
protected void Page_Load(object sender, EventArgs e)
{
cnn.ConnectionString= ConfigurationManager.ConnectionStrings["con"].ConnectionString;
if(!IsPostBack)
{
// This will only happen when the page is first loaded, as the first time is not considered a post back, but all others are
dr1 = TableUtoP();
dtWordsList.Load(dr1);
}
}
Only fill the dataTable if it's not a PostBack... 只有当它不是PostBack时才填充dataTable ...
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//TO DO: Make the call to fill the data table here
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.