Last post May 15, 2017 09:50 AM by Leon Davis
May 10, 2017 08:14 AM|vickeynet123|LINK
I have a table (tbl_datasourceinfo) in database where I have the details of three different databases.
The field name of the table are tableid,datasourcename and sqlqueryname.
The Connection String will be there in the column DatasourceName and the Select query (select * from table1) will be there in the column sqlqueryname.
From dotnet C# code I need to execute these three select queries in the table (tbl_datasourceinfo)and write the results to excel sheet. Can anyone help me with the logic or sample code please?
May 10, 2017 08:53 AM|Eric Du|LINK
After read your description, as far as I know, you could refer to the following steps:
1. you could save the tbl_datasourceinfo record in the datatable, then pass the table name to the select method(call three times according to the number of table name).
2. you could refer to the following code to get the data from the database, then bind it to the gridview.
string connection = ConfigurationManager.ConnectionStrings["connectstringname"].ConnectionString;
SqlConnection conn = new SqlConnection(connection);
string newquerycommand = "query cmd";
SqlCommand newcmd = new SqlCommand(newquerycommand, conn);
SqlDataAdapter newadapter = new SqlDataAdapter(newcmd);
DataTable dt = new DataTable();
GridView1.DataSource = dt;
3. Please refer to this sample about export the gridview to excel.
Export GridView to Excel in ASP.Net with Formatting using C# and VB.Net:
May 15, 2017 09:50 AM|Leon Davis|LINK
You can try using 3rd party tool to easily achieve this task. Refer below article: