Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.
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
-
dbrewerton
-
- Posts: 12
- Joined: Thu Nov 14, 2019 4:07 pm
- Location: Honeoye, NY, USA
Thu Jan 09, 2020 3:45 am
Hi,
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();
command.CommandText
= " 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,
Amber
E-iceblue support team
-
Amber.Gu
-
- Posts: 525
- Joined: Tue Jun 04, 2019 3:16 am