过滤表达式' 1'不评估为布尔术语。如何解决这个错误。当我点击按钮时,只出现了这个错误
public DataSet Fill_Dataset()
{
DataSet ds = new DataSet();
con = new SqlConnection(str);
con.Open();
cmd = new SqlCommand("sp_new", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
DataView dv = ds.Tables[1].DefaultView;
if(ds.Tables[0].Rows.Count>1)
{
for (int i = 0; i < ds.Tables[0].Rows.Count;i++ )
{
DataRow dr = ds.Tables[0].Rows[i];
DataTable dt1;
dv.RowFilter=dr["country_id"].ToString();
dt1 = dv.ToTable();
ds.Tables.Add(dt1);
}
}
return ds;
}
protected void excel_generation_Click(object sender, EventArgs e)
{
try
{
Export_Excel();
}
catch (Exception ex)
{
throw ex;
}
}
void Export_Excel()
{
con = new SqlConnection(str);
con.Open();
DataSet ds = Fill_Dataset();
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(ds);
wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
wb.Style.Font.Bold = true;
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=Summary_Rpt.xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
}
答案 0 :(得分:0)
DataSet ds = new DataSet(); DataSet dstemp = new DataSet();
con = new SqlConnection(str);
con.Open();
cmd = new SqlCommand("sp_new", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
DataView dv = ds.Tables[1].DefaultView;
if(ds.Tables[0].Rows.Count>1)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow dr = ds.Tables[0].Rows[i];
dv.RowFilter = "country_id = " + dr["country_id"];
dstemp.Tables.Add(dv.ToTable(dr["country_name"].ToString()));
}
}
return dstemp;