0

I need to import data from an excel file into my SQL Server Database. The datafile contains about 120,000 records(rows) that I need to import. Each row of data in the excel file consists of about 183 formatted columns of data, and the data is to be dispersed to about 13 different tables on the SQL end. What would be the best way(easiest but high performance) to import all those records to the SQL, making sure that each row is properly processed.

Another option is to have an option that loads the data into a temp data table in a Database, and then run the script to move all columns of data from the temp table into the various other tables.

1 Answer 1

2

I use this way to get data from CSV file :->

      int f = 0;
 var reader = new StreamReader(File.OpenRead(@ExcelFilePath));
                Buisness_logic bl = new Buisness_logic();

                while (!reader.EndOfStream)
                {
                       if (f == 0)
                    {
                         var line = reader.ReadLine();
                        f++;
                    }
                    else
                    {
                        var line = reader.ReadLine();
                        string[] s = line.Split(',');
                        count = s.Length;
                        if (s.Length == 3)
                        {
                            var values = line.Split(',');
                            string query = "Insert into Events_party values('" + identity + "','" + values[0] + "','" + values[1] + "','" + values[2] + "','" + time + "','" + dt + "')";
                            bl.ExecuteQuery(query);
                            count = 101;
                        }
                        else
                        {
                            MessageBox.Show("Imported File was not in defined format !! ", ".File Format Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            textBox1.BackColor = Color.Pink;
                            break;
                            count = 100;
                        }
                    }
                }
Sign up to request clarification or add additional context in comments.

1 Comment

How efficient is this when importing almost 120000 lines?

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.