Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在itextsharp pdf creator中将sql查询数据添加到表中?_C#_Asp.net_Sql_Itextsharp - Fatal编程技术网

C# 如何在itextsharp pdf creator中将sql查询数据添加到表中?

C# 如何在itextsharp pdf creator中将sql查询数据添加到表中?,c#,asp.net,sql,itextsharp,C#,Asp.net,Sql,Itextsharp,我的数据库中有多个表,我需要从中检索数据,然后将每个表添加到pdf表中的单个单元格中。我的代码如下。我已经创建了select语句。现在,我需要得到每个语句并将它们放在各自的单元格中,所以关于我的内容在第2列第1行,教育内容在第2列第2行等等 有什么想法吗 protected void pdfcreatorbtn_Click(object sender, EventArgs e) { //setup connection to SQL and retriev

我的数据库中有多个表,我需要从中检索数据,然后将每个表添加到pdf表中的单个单元格中。我的代码如下。我已经创建了select语句。现在,我需要得到每个语句并将它们放在各自的单元格中,所以关于我的内容在第2列第1行,教育内容在第2列第2行等等

有什么想法吗

protected void pdfcreatorbtn_Click(object sender, EventArgs e)
        {
            //setup connection to SQL and retrieve data
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RIADDConnectionString"].ConnectionString);
                SqlCommand aboutmecmd    = new SqlCommand ("SELECT about_me FROM about_me",conn);
                SqlCommand educationcmd  = new SqlCommand ("SELECT education_name, details FROM education",conn); 
                SqlCommand employmentcmd = new SqlCommand ("SELECT job_name,details_emp,Year_started,year_finished FROM employment",conn);
                SqlCommand hobbiescmd    = new SqlCommand ("SELECT hobby_type,details_h FROM hobbies",conn);
                SqlCommand skillscmd     = new SqlCommand ("SELECT skill,rating FROM skills",conn);

            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();




            Document doc = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35);
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("MatthewCremonaCV.PDF", FileMode.Create));
            doc.Open(); //open document file

            PdfPTable maintable = new PdfPTable(2); //declare new table
                maintable.AddCell("image"); //col 1 row 1
                maintable.AddCell(""); //col 2 row 1
                maintable.AddCell("About Me"); //col 1 row 2
                maintable.AddCell(""); //col 2 row 2
                maintable.AddCell("Education"); //col 1 row 3
                maintable.AddCell(""); //col 2 row 3
                maintable.AddCell("Skills"); //col 1 row 4
                maintable.AddCell(""); //col 2 row 4
                maintable.AddCell("Employment History"); //col 1 row 5
                maintable.AddCell(""); //col 2 row 5
                maintable.AddCell("Hobies"); //col 1 row 6
                maintable.AddCell(""); //col 2 row 6
                maintable.AddCell("Contact"); //col 1 row 7
               // maintable.AddCell("Mobile: 123456"\n"email:matthewriadd@gmail.com"); //col 2 row 7
            doc.Add(maintable);

            PdfPTable table = new datatable()

            doc.Close();

您需要将结果集作为DataTable/DataSet返回

var ds = new DataSet();
var da = new SqlDataAdapter(<command>);
da.Fill(ds);
请记住,返回的对象是一个对象,因此请确保转换为适当的类型

mainTable.AddCell(aboutMe.ToString());
mainTable.AddCell(aboutMe.ToString());