-1

We have an admin panel which uses php to insert rows into a mysql db but we can only insert one row at a time. We have hundreds of teachers who create hundreds of sentences and answers per week. How can we do a batch insert ie: They would create sentences in a spreadsheet or a c# utility and then would need to "upload" those sentences into mysql db. Not too sure how do do it and would welcome info. Thanks.

Link found in stackoverflow Batch insertion of data to MySQL database using php

OK so I load a text file via php or I can use code in php which loops through each row and inserts it in the db.

So my question is if c# can do this and if not... 1. Each teacher copies and pastes their rows from their spreadhseet into a utility. 2. Export to a file that can then be uploaded to my db using php.

Community
  • 1
  • 1
user3149225
  • 93
  • 1
  • 11

3 Answers3

0

Maybe you need it?

INSERT INTO `tbl` (`name`, `age`) VALUES ("name 1", 10), ("name 2", 11)

Insert many records at one time

Veniamin
  • 459
  • 2
  • 9
0
$Q0 = array();
$query0 = "INSERT INTO Table (`col1`,`col2`,`col3`) VALUES ";

            foreach($Q0 as $value0)
            {
                    $query0 .= "('$val1','$val2','$value0'),";
            }

            $query0 = substr_replace($query0, "", -1);
            mysqli_query($conn, $query0);

Sahil Roy
  • 3
  • 1
  • 3
0

Yes you can do it in c#. First you need to give your teachers an excel format so they could fill the data (by an excel format I mean a blank excel file which has only column headers and they can fill the rows). Here is a couple of links that shows you how to get your data from excel.

C# - How do I iterate all the rows in Excel._Worksheet?

Row Looping in Excel

Then you can save the data in your database. This might give you and idea about how to do it.

How do I to insert data into an SQL table using C# as well as implement an upload function?

Armin
  • 576
  • 6
  • 13