I have in the bank the registration of the building, with the amount of rooms qtdSala
, among others. I'm trying to insert, in another grid, each room according to the value entered in qtdSala
, to register in the rooms table, through a for, so I tried like this:
private void CriarSalas(int nSalas)
{
for (int i = 0; 1 < nSalas; i++)
{
try
{
SqlConnection con = new SqlConnection(conexaoString);
SqlCommand cmd = new SqlCommand(@"INSERT INTO salas
(nomeSala)
VALUES
(@nomeSala)", con);
cmd.Parameters.AddWithValue("@nomeSala", i);
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
//Atualiza Grid
this.salasTableAdapter.Fill(this.bdDataSet.salas);
SqlConnection con = new SqlConnection(conexaoString);
con.Close();
con.Dispose();
}
}
}
It does not work, I'm not sure how to reference nsalas
...
It should take qtdsalas
, 20 for example, and create sala01
, sala02
... to sala20
. Follow the table template:
TABELA SALAS
____________________________
| Id | IdPredio | NomeSala |
| 23 | 05 | "Sala01" |
| 24 | 05 | "Sala02" |
| 25 | 05 | "Sala03" |
| 26 | 05 | "Sala04" |