I have created a SQL database named: DateTimes.
The database is now filled in with this information seen on this image:

As seen in the DateTime column, we can see those DateTime values in ascending order:
201005011600
201005011630
201005011645
201005011700
Now comes the problem, I wonder how to do. As we can see the rows are in DateTime ascending order and now I have a new record that have this DateTime that I want to add to the table:
201005011615
The code I have so far below only ADDS a row at the very end of the table.
I do have 2 questions here:
I now want to insert this record in the correct row which will be the second row in the DataTable. Which means that this record will be inserted at the correct index in the Table (DateTime ascending order)
How is this possible to do?Looking at the code, I use:
comm.Parameters.Add(new SqlParameter...5 times. What I wonder here is since I could have many thousands of columns later. If there will be a faster way to.Addall info for all columns here in some kind of batch here instead. Which would mean, 1 .Add, instead of 5 .Adds?void insertvalue() { string connectionString = GetConnectionString(); string cmdString = "INSERT INTO DateTimes (DateTime,F1,F2,G1,G2) VALUES (@val1, @val2, @val3, @val4, @val5)"; using (SqlConnection conn = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = cmdString; comm.Parameters.Add(new SqlParameter("@val1", 201005011615)); comm.Parameters.Add(new SqlParameter("@val2", 0.05044)); comm.Parameters.Add(new SqlParameter("@val3", 0.05044)); comm.Parameters.Add(new SqlParameter("@val4", 0.05044)); comm.Parameters.Add(new SqlParameter("@val5", 0.05044)); try { conn.Open(); int i = comm.ExecuteNonQuery(); if (i != 0) { MessageBox.Show(i + "Data Saved"); } } 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"; }
ORDER BYclause you use when selecting.ORDER BYtheDateTimecolumn somehow?