HI,
I have to build the application which trafers the data from SQL Server to Existed Excel file. Now i get the data from SQL File but i dont know how to put that data into Already existed Excel file. Can you please help me.. Thanks in advance..
HI,
I have to build the application which trafers the data from SQL Server to Existed Excel file. Now i get the data from SQL File but i dont know how to put that data into Already existed Excel file. Can you please help me.. Thanks in advance..
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Bechir BejaouiRank #144 · 15.9K reputationPosted Dec 21, 2008, 6:55 AM EST
finally, you can call this procedure from within your C# code
This is the style of your SP
CREATE PROCEDURE ExportToExcel
(
@filepath nvarchar(100), -- OK you can change from 100 to the numenr that --fits your needs
@sheetname nvarchar(50)
)
INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 11.0;Database=C:\' + @filepath + ';',
'SELECT Name, Date FROM [' +@sheetname+ ']') SELECT * FROM yourdataTable
then you can call the stored procedure from within the C# code
string ConnectionString ="Integrated Security=SSPI;Initial Catalog=databasename;Data Source=servername;";
ExportToExcelSqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand StoredProcedureCommand = new SqlCommand("
", conn);StoredProcedureCommand.CommandType = CommandType.StoredProcedure;
SqlParameter myParm1 = StoredProcedureCommand.Parameters.Add( "@filepath
", SqlDbType.String);
myParm1.Value = @"C:\myfile.xlsx";
SqlParameter myParm2 = StoredProcedureCommand.Parameters.Add("@sheetname", SqlDbType.String);
myParm2.Value = "sheet$1";
conn.Open();
StoredProcedureCommand.excutenonequery;Mohan Energy3 reputationPosted Dec 21, 2008, 5:53 PM EST
Bechir BejaouiRank #144 · 15.9K reputationPosted Dec 22, 2008, 12:17 AM EST