0

i have extracted the names from database and displayed them on web page.Now I wish to insert those names into excel sheet.how can i do that? please help

1 Answer 1

2

This works fine.

string connectionString = "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=D:\\ConsoleApp\\Books1.xls; FIRSTROWHASNAMES=0;READONLY=FALSE;";

DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.Odbc");           
using (DbConnection connection = factory.CreateConnection())
{
    connection.ConnectionString = connectionString;

    using (DbCommand command = connection.CreateCommand())
    {
        command.CommandText = "INSERT INTO [Sheet1$](id,name) VALUES('2', 'test')";

        connection.Open();
        command.ExecuteNonQuery();
    }

}
Sign up to request clarification or add additional context in comments.

1 Comment

what is [Sheet1$] and Dbq mean?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.