0
I have an app that takes information from a TextBox
, inserts into a list List<>
and then shows in a CheckBoxList
.
Example:
List<string> quantidade = new List<string>();
for (int i = 0; i < CheckBoxListLinhas.Items.Count; i++)
{
quantidade.Add(TextBoxQuantidade.Text.ToString());
}
List<string> artigo = new List<string>();
for (int i = 0; i < CheckBoxListLinhas.Items.Count; i++)
{
artigo.Add(TextBoxArtigo.Text.ToString());
}
List<string> valor = new List<string>();
for (int i = 0; i < CheckBoxListLinhas.Items.Count; i++)
{
valor.Add(TextBoxValor.Text.ToString());
}
/*List<string> artigo = new List<string>();
for (int i = 0; i < CheckBoxListLinhas.Items.Count; i++)
{
artigo.Add(TextBoxArtigo.Text.ToString());
}*/
CheckBoxListLinhas.Items.Add(new ListItem("Quantidade: " + TextBoxQuantidade.Text + " Artigo: " + TextBoxArtigo.Text + " Valor: " + TextBoxValor.Text) + " Anexo: " + FileUpload1.FileName.ToString());
And I want to add to the database all the rows inserted in List<>
and I already have this example:
SqlCommand sqlInsertList = new SqlCommand("Insert into linhas (quantidade,descricao,valor) VALUES(@quantidade,@descricao,@valor)", sqlConn);
sqlInsertList.Parameters.AddWithValue("@quantidade", );
sqlInsertList.Parameters.AddWithValue("@descricao", TextBoxArtigo.Text);
sqlInsertList.Parameters.AddWithValue("@valor", float.Parse(TextBoxValor.Text, CultureInfo.InvariantCulture.NumberFormat));
sqlConn.Open();
sqlTran = sqlConn.BeginTransaction();
sqlInsert.Transaction = sqlTran;
sqlInsert.ExecuteNonQuery();
sqlTran.Commit();
What is the easiest way to do this and adapt the SQLInsert
?
Are you having any problems? It seems to be ok, just need to complete a line.
– Maniero
I advise that instead of using three lists, create only a typed list with the Line class. It will be easier to go through only one enumerable than to work with three of them synchronized.
– Gabriel Katakura