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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bechir BejaouiPosted Dec 21, 2008, 11:55 AM
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;Bechir BejaouiPosted Dec 22, 2008, 5:17 AM
Mohan EnergyPosted Dec 21, 2008, 10:53 PM