1
I have a form in C#:
On this form there is a textbox
where I enter the day of the week and a datagrid
where I type in the hours.
I put a column call time, with DataGridViewCellStyle { Format=t }
manual. But the mask __:__
is not appearing at runtime. I am using the following loop to save.
void INSERIRHORARIO()
{
//Instância da conexão onde passo a
//ConnectionString
var conn = new MySqlConnection("Persist Security Info=False;Server=10.1.1.50;database=sistema_escola;uid=alfa;pwd=;");
// //sql que será executado na tabela cliente
var sql = "INSERT INTO dia_hora (dia, horario, qtdVagas) " +
"VALUES (@dia, @horario, @qtdVagas)";
//instância do comando onde passo
//o sql e a conexão como parâmetro
var cmd = new MySqlCommand(sql, conn);
//abro a conexão
strSelect = "SELECT SUM(qtdVagas) AS Vagas FROM laboratorio";
DataTable tabela;
tabela = conexao.ExecultarSelect(strSelect);
conn.Open();
//percorro o DataGridView
for (int i = 0; i < dGVHorario.Rows.Count - 1; i++)
{
//limpo os parâmetros
cmd.Parameters.Clear();
//crio os parâmetro do comando
//e passo as linhas do dgvClientes para eles
//onde a célula indica a coluna do dgv
cmd.Parameters.AddWithValue("@dia", txtDiadaSemana.Text);
//dGVHorario.Rows[i].Cells[0].Value);
cmd.Parameters.AddWithValue("@horario", dGVHorario.Rows[i].Cells[0].Value);
cmd.Parameters.AddWithValue("@qtdVagas", tabela.Rows[0]["Vagas"].ToString());
//executo o comando
cmd.ExecuteNonQuery();
}
//Fecho conexão
conn.Close();
But, I’m working with object orientation, so I already have a class for connection, and a class for registering schedules. How to loop to take the connection from my class and send the data to the time class?
Day class
public class dia_hora : ModeloCrud {
private string dia;
private string horario;
private int qtdVagas;
public string Dia
{
get { return dia; }
set { dia = value; }
}
public string Horario
{
get { return horario; }
set { horario = value; }
}
public int QtdVagas
{
get { return qtdVagas; }
set { qtdVagas = value; }
}
}
If you put the class connection and class to register time I can help you, but the code above has a fruit salad, because it opens with the
conn
In the middle of the code there’s aconexao
, must be wrong something, well as I said make the classes available!– Maria
Time Clesse public class dia_hora : Modelocrud { private string dia; private string horario; private int qtdVagas; public string Dia { get { Return dia; } set { dia = value; } } public string Time { get { Return time; } set { time = value; } } public int Qtdvagas { get { Return qtdVagas; } set { qtdVagas = value; } }
– Fabrício Mendes
Place by editing your question: http://answall.com/posts/28827/edit
– Maria
The connection class doesn’t fit here. But it does connect to the bank. kkkk
– Fabrício Mendes
Fabricio gives yes look there I edited and put the class dia_hora.
– Maria
Maria Bem, the class of dia_horario the class that makes the persistence of information in the bank. As I put above. I have an automatic Insert it takes the attributes and automatic values of the classes so I have to pass the data there. The kind that the code is on top he’s recording in the bank, but he thought if I have to change the server path, where the code is, I’ll have to change it. so oo.
– Fabrício Mendes
Just a tip friend Fabricio, when I saw it here
dia_hora : ModeloCrud
has already given me subsidies to say that your model may be functional, but, out of the standard and are little information for anyone to answer, sorry like the stimulus, but, I had to make a constructive criticism... Sorry again!– Maria
quiet, I really need how to make this information pass through the class without making a direct connection. As it is up there
– Fabrício Mendes
Ala maria again. Thanks for the tip I’ll let my solution in baico really worth
– Fabrício Mendes