0

i want to insert my xls file sheet into the ODBC server in c# .....kindly help me out with its c# coding....I can only find sql server related problems in the internet as i want to work in ODBC. this is my coding :-

    string ConnectionString, str;

    OdbcConnection con;

    OdbcCommand cmd;

    SqlBulkCopy bkcp ;

    private void btnSend_Click(object sender, EventArgs e)
    {
        string ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=ak_db.excel_table;Uid=root;Pwd=root";

        using (OdbcCommand cmd = new OdbcCommand(ConnectionString))
        {

            OdbcCommand command = new OdbcCommand("Select * FROM [Sheet1$]", con);

            con.Open();

            // Create OdbcDataReader to Data Worksheet

            using (OdbcDataReader dr = cmd.ExecuteReader())
            {

                // SQL Server Connection String

                string OdbcConnectionString = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=ak_db.excel_table;Uid=root;Pwd=root";

         }

i dont know what to do after this ...so kindly help me out....

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
akk
  • 45
  • 1
  • 1
  • 6

1 Answers1

1

One way to go is to read the values from your excel file and store them in a dataset like described here:

Reading-Excel-Files-From-C-Sharp

and then writing this dataset to your online database:

saving-dataset-to-database

Good Luck!

Community
  • 1
  • 1
XikiryoX
  • 1,898
  • 1
  • 12
  • 33
  • itz same as above...,..actually m nt able to append the code from the link into my code..... – akk Oct 21 '13 at 09:14
  • Well I'm not gonna write the code for you, I am willing to point you in the right direction. Try the following to start.. You have a connectionstring and your oledb command, so far so good, now create a dataset and fill it up, you can follow this link: http://msdn.microsoft.com/en-us/library/aa288452(v=vs.71).aspx you should be able to do this now. – XikiryoX Oct 21 '13 at 09:39