Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents from any .NET(C#, VB.NET, ASP.NET, .NET Core) application and Java (J2SE and J2EE) application.

Wed Jan 08, 2020 1:26 pm

Greetings, in numerous examples the data will come from a text file. What I'd like to do is pull this data from a SQL Server database. I've configured the c# code behind connection string object and I did find one that shows pulling from OleDB, how do I pull from Sql for data? I'm including additional information below for clarification.

This is the connection string I've set up for this purpose pulling the data from App.config.

SqlConnection sqlconn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString);

How do I load the results from my query into a DataTable using a DataAdapter? Many thanks!
Dan Brewerton, MIS
Cybersecurity Specialist
.NET Programmer
User avatar

Posts: 12
Joined: Thu Nov 14, 2019 4:07 pm
Location: Honeoye, NY, USA

Thu Jan 09, 2020 3:45 am


Thanks for your inquiry.
Please try the code below to connect the Database and export the data into a data table.
Code: Select all
             SqlConnection sqlconn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString);
            SqlCommand command = new SqlCommand();
                    = " SELECT * "
                    + " FROM tableName";
            DataSet dataSet = new System.Data.DataSet();
            SqlDataAdapter dataAdapter = new SqlDataAdapter(command.CommandText, sqlconn);
            dataAdapter.Fill(dataSet, " tableName ");
            System.Data.DataTable dt = dataSet.Tables["tableName "];

Best wishes,
E-iceblue support team
User avatar

Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.Presentation