The issue I am having is the values from are not being passed into my array correctly. I've done a Response.Write to check and I have the correct data. I can not seem to get this to pass into my array or the database correctly.My goal is to pass ID and P into an array and in the for loop through them then output the corresponding data. What is showing up for P is 0. I am using razor C# without MVC.
- else if (Page == "2")
- {
- int foo;
- string paramName = "";
-
-
- using (SqlConnection connect = new SqlConnection(conn.strConn))
- {
- connect.Open();
- using (SqlCommand comm = new SqlCommand(conn.SQL, connect))
- {
- using (SqlDataReader reader = comm.ExecuteReader())
- {
- reader.Read();
- foo = Convert.ToInt32(reader["bar"]);
- }
- }
- }
-
- string[] ID = new string[foo];
- double[] P = new double[foo];
-
- i = 0;
-
- if (!HttpContext.Current.Request["bar"].IsEmpty())
- {
- foreach (var selection in HttpContext.Current.Request["bar"].Split(','))
- {
- IDs[i] = selection.ToString();
- ID = selection.ToString();
- paramName = "P" + ID;
- Ps[i] = Convert.ToDouble(HttpContext.Current.Request[paramName]);
- P = Convert.ToDouble(HttpContext.Current.Request[paramName]);
- i++;
-
-
- conn.SQL = "Insert Into Table (ID, Date, Number ) Values (@ID, @Dt, @Nm)";
-
- using (SqlConnection connection = new SqlConnection(conn.strConn))
- {
- connection.Open();
- using (SqlCommand comm = new SqlCommand(conn.SQL, connection))
- {
-
- comm.Parameters.AddWithValue("@ID", ID);
- comm.Parameters.AddWithValue("@Dt", DateTime.Now);
- comm.Parameters.AddWithValue("@Nm", Math.Round(P, 2));
-
-
- comm.ExecuteNonQuery();
- }
- }
- }
- conn.SQL = "Select Name, Name1 From Table2 Where ID = @ID";
-
- >
-
class
="d0"> -
"250px" | >Name - Data
-
- @for (int x = 0; x < i; x++)
- {
- using (SqlConnection connection = new SqlConnection(conn.strConn))
- {
- connection.Open();
- using (SqlCommand comm = new SqlCommand(conn.SQL, connection))
- {
- comm.Parameters.AddWithValue("@ID", IDs[x]);
- using (SqlDataReader reader = comm.ExecuteReader())
- {
- reader.Read();
-
-
class
="d@((x+1)%2)"> - @(reader["Name"] + " " + reader["Name1"])
- @Ps[x].ToString("c")
-
-
-
- }
- }
- }
- }
-
-
- }
- }