为什么数据集没有加载表中的第一行 [英] Why is dataset not loading first row in table
本文介绍了为什么数据集没有加载表中的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个存储过程,我有一个在页面加载时在gridview(BenReport)上显示表数据,另一个(spTest)从表中提取数据并将数据放入数据集中然后被提取使用openofficexml来优化。问题是我的表中的第一行被跳过,我在sql上运行存储过程并返回所有行。不知道为什么它跳过第一排
我尝试过:
这里是我的代码:
i have a two stored procedures,i have one that displays table data on a gridview (BenReport) on page load and another one (spTest) that extacts data from a table and i put that data in a dataset which then is extracted to excel ts using openofficexml . the problem is that the first row in my table is being skipped , i ran the stored procedure on sql and all the rows are returned. not sure why its skipping the first row
What I have tried:
here is my code:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
SqlCommand command = new SqlCommand("BenReport", con) { CommandType = System.Data.CommandType.StoredProcedure };
SqlDataAdapter sda = new SqlDataAdapter();
command.Connection = con;
sda.SelectCommand = command;
DataSet ds = new DataSet();
sda = new SqlDataAdapter("BenReport", con);
sda.Fill(ds);
GRDBencount.DataSource = ds.Tables[0];
GRDBencount.DataBind();
con.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
ExtractBen();
}
public void ExtractBen()
{
SqlConnection connex = new SqlConnection(strConnString);
SqlCommand command = new SqlCommand("spTest", connex) { CommandType = System.Data.CommandType.StoredProcedure };
SqlDataAdapter sda = new SqlDataAdapter();
command.Connection = connex;
sda.SelectCommand = command;
command.CommandTimeout = 600;
DataSet ds = new DataSet();
sda = new SqlDataAdapter("spTest", connex);
sda.Fill(ds);
if (ds.Tables.Count > 0)
{
MemoryStream ms = new MemoryStream();
int i = 1;
using (ExcelPackage package = new ExcelPackage(ms))
{
foreach (DataTable table in ds.Tables)
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("sheet" + i++);
if (worksheet.Name == "sheet1")
{ worksheet.Name = "Bencount"; }
if (worksheet.Name == "sheet2")
{ worksheet.Name = "validateWages"; }
if (worksheet.Name == "sheet3")
{ worksheet.Name = "BeneficiariestobeExctracted"; }
if (worksheet.Name == "sheet4")
{ worksheet.Name = "Beneficiaries_with_0_Wdays"; }
if (worksheet.Name == "sheet5")
{ worksheet.Name = "beneficiaries_with_wages_but_no_account_numbers"; }
if (worksheet.Name == "sheet6")
{ worksheet.Name = "account_number>11_characters/wages<100"; }
if (worksheet.Name == "sheet7")
{ worksheet.Name = " beneficiary_appear on more than project for the same month"; }
if(worksheet.Name == "sheet8")
{ worksheet.Name = "account_number_shared_by_more_than_one_beneficiary"; }
if (worksheet.Name == "sheet9")
{ worksheet.Name = "beneficiary_appear_on_more_than_project_for_the_same_month"; }
if (worksheet.Name == "sheet10")
{ worksheet.Name = "Missing_Beneficiaries"; }
worksheet.Cells["A1"].LoadFromDataTable(table, true);
worksheet.Cells["A1:Z1"].AutoFitColumns();
worksheet.Cells["A1:Z1"].Style.Font.Bold = true;
}
Response.Clear();
package.SaveAs(Response.OutputStream);
Response.AddHeader("content-disposition", "attachchment; filename=BeneficiaryDetails.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
Response.End();
}
}
}
推荐答案
复制完整的ds,如下所示,让我知道它是否有效,
GRDBencount.DataSource = ds;
谢谢。
Copy the Complete ds as below, let me know if it works,
GRDBencount.DataSource = ds;
Thank you.
这篇关于为什么数据集没有加载表中的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文