大家。我有这个简单的WebApp,它有一个报表查看器,可以显示我的查询结果。我编写了应该通过我的select查询获取数据的代码。然后我写了一个小方法,应该在报表查看器上显示我的记录。我究竟做错了什么?
protected void Button1_Click(object sender, EventArgs e)
{
showReport();
}
protected void showReport()
{
rptViewer.Reset();
DataTable dt = GetData(Convert.ToInt64(TextBox1.Text));
ReportDataSource rds = new ReportDataSource("DataSet1", dt);
rptViewer.LocalReport.DataSources.Add(rds);
rptViewer.LocalReport.ReportPath = "Report1.rdlc";
ReportParameter rptParam = new ReportParameter("id_doc", TextBox1.Text);
rptViewer.LocalReport.Refresh();
}
private DataTable GetData(Int64 id_doc)
{
DataTable dt = new DataTable();
string connStr = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["logindbConnectionString"].ConnectionString;
try
{
using (var conn = new SqlConnection(connStr))
{
string sSQL = "select * from doc_details where id_doc=";
SqlCommand cmd = new SqlCommand(sSQL+ TextBox1.Text, conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@id_doc", SqlDbType.BigInt).Value = TextBox1.Text;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
Console.WriteLine(dt);
adp.Fill(dt);
}
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
return dt;
}
答案 0 :(得分:0)
试试这个
查询必须具有名为string @id_doc
的参数string sSQL =" select * from doc_details,其中id_doc = @ id_doc&#34 ;;
SqlCommand cmd = new SqlCommand(sSQL,conn);
command.Parameters.Add(new SqlParameter(" @ id_doc",TextBox1.Text));