I have a general question that I have not found any answer to. I think it is important to ask this question so I know how to structure the whole application so I am on the right track from the very beginning.
I believe it is practical/efficient to add Multiple rows in one Query command. The below code adds 3 rows with 5 values in 5 columns at once.
See this image also of the table:

My question now is. This table will later have 100,000 columns where I am thinking of for example adding 10 rows at a time. Now imagine that this cmdString will be EXTREMELY long.
My question simply is. Is this okay or is this the wrong way to go here when I add so much information in one query? (Is this the fastest way to do it or should I do the below code in another way?)
Thank you!
void addMultipleRowWithValuesSQL()
{
String cmdString = "INSERT INTO DateTimes(DateTime,F1,F2,G1,G2) " +
"VALUES" +
"('201005011715','1',2,'3','4')," +
"('201005011730','5',6,'7','8')," +
"('201005011745','9',10,'11','12');";
using (SqlConnection conn = new SqlConnection(GetConnectionString()))
{
using (SqlCommand comm = new SqlCommand(cmdString))
{
try
{
comm.Connection = conn;
conn.Open();
int i = comm.ExecuteNonQuery();
if (i != 0)
{
MessageBox.Show(i + "Rows Added");
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
static private string GetConnectionString()
{
return "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\andre\\source\\repos\\TestDatabaseCreation\\DatabaseTest.mdf;Integrated Security=True;Connect Timeout=30";
}
batch insertis the way to go. I am not familiar of how to do that, but perheps there is an example somewhere then. I thought about that also, that it has to be enormous amount of parsing with such a long string.batch insertof my code example. It would be very useful to see how that could be done? The speed improvement seems to be very big using that.