0

I have a button which make it add data to accees database,but i want to another button which will make export data from access to excel.

here is my button :

try
        {
            string cmdText = "Insert INTO data(Name,Mail) Values(?,?)";
            db_conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Alpozkanm\\Documents\\Visual Studio 2012\\WebSites\\IntegratedSubscribeSystem\\veri.accdb;Persist Security Info=False;");
            OleDbCommand db_command = new OleDbCommand(cmdText, db_conn);
            db_conn.Open();
            db_command.Parameters.AddWithValue("@p1", TextBox1.Text);
            db_command.Parameters.AddWithValue("@p2", TextBox2.Text);
            db_command.ExecuteNonQuery();
            Label5.Text = "Succesfully!";
        }
        catch (Exception ex)
        {
            Response.Write("There is something wrong!" + ex.Message);
        }

What is the second button codes ?

Any Suggestion ?

BTW,

I use visual studio 2012,Access and Excel 2010
2
Contributors
1
Reply
23
Views
3 Years
Discussion Span
Last Post by du_1
0

Hello, here is my solution to export data to Excel with a .NET Excel library

//Connect DataBase and Export Data to DataTable
            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\data\demo.mdb";
            conn.Open();
            OleDbCommand command = new OleDbCommand();
            command.CommandText
                = " select Name, Capital, Continent, Area, Population, from country ";
            command.Connection = conn;
            OleDbDataAdapter adapter = new OleDbDataAdapter(command);
            DataTable dataTable = new DataTable();
            adapter.Fill(dataTable);

            //Create Excel
            Workbook book = new Workbook();
            Worksheet sheet = book.Worksheets[0];

            //Export Data from DataTable to Excel
            sheet.InsertDataTable(dataTable, true, 1, 1);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.