Buen día, estoy tratando de enviar el arreglo sn a SQL SERVER pero me sale el error
The parameterized query '(@Serial_Number nvarchar(4000))INSERT INTO Auditorias (Serial_Nu' expects the parameter '@Serial_Number', which was not supplied.
Adjunto el código, se manda cuando se hace clic en el botón "Approve":
public partial class Audit : System.Web.UI.Page
{
List<string> Serial_Number = new List<string>();
List<string> User_SSO = new List<string>();
List<string> User_Name = new List<string>();
string[] sn = new string[5];
string[] sso = new string[5];
string[] user = new string[5];
int i = 0;
public void Page_Load(object sender, EventArgs e)
{
StringBuilder table = new StringBuilder();
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ITTESTDBConnectionString"].ToString();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT TOP 5 Brand, Model, Service_Tag, Hostname, User_SSO, User_Name, Memory, HD, OS FROM Laptops ORDER BY NEWID()";
cmd.Connection = con;
SqlDataReader rd = cmd.ExecuteReader();
table.Append("<table border='1'>");
table.Append("<tr><th>Brand</th><th>Model</th><th>Service Tag</th><th>Hostname</th><th>User SSO</th><th>User Name</th><th>Memory</th><th>HDD</th><th>Operative System</th>");
table.Append("</tr>");
if (rd.HasRows)
{
while (rd.Read())
{
table.Append("<tr>");
table.Append("<td>" + rd[0] + "</td>");
table.Append("<td>" + rd[1] + "</td>");
table.Append("<td>" + rd[2] + "</td>");
table.Append("<td>" + rd[3] + "</td>");
table.Append("<td>" + rd[4] + "</td>");
table.Append("<td>" + rd[5] + "</td>");
table.Append("<td>" + rd[6] + "</td>");
table.Append("<td>" + rd[7] + "</td>");
table.Append("<td>" + rd[8] + "</td>");
Serial_Number.Add(rd[2].ToString());
}
}
string[] sn = Serial_Number.ToArray();
table.Append("</table>");
PlaceHolder1.Controls.Add(new Literal { Text = table.ToString() });
rd.Close();
}
}
public void btnApprove_Click(object sender, EventArgs e)
{
for (i=0; i<5; i++)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ITTESTDBConnectionString"].ToString();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO Auditorias (Serial_Number, Estado) VALUES (@Serial_Number,'Correcto')";
cmd.Connection = con;
cmd.Parameters.AddWithValue("@Serial_Number", sn[i]);
cmd.ExecuteNonQuery();
}
}
}