0
I’m creating a cafeteria system.
I created the login system and it’s working, when I went to create a page to create the logins, I’m having difficulties in converting the int
for string
- the txtNivel.Text
does not come out of the red, follow the codes:
public int Codigo = 0;
private void Gravar(string Login, string Senha, int Nivel, string InfAdicionais)
{
try
{
Dados objDados = new Dados();
objDados.Gravar(Login, Senha, Nivel, InfAdicionais);
txtLogin.Clear();
txtSenha.Clear();
txtNivel.Clear();
txtInfAdicinais.Clear();
string menssagem = "Seus dados foram gravados com sucesso.";
MessageBox.Show(menssagem);
}
catch (Exception ex)
{
MessageBox.Show("Ocorreu um erro: " + ex.Message);
}
}
private void btn_Adicionar_Click(object sender, EventArgs e)
{
{
if(!String.IsNullOrEmpty(txtLogin.Text) &&
!String.IsNullOrEmpty(txtSenha.Text) &&
!String.IsNullOrEmpty(txtNivel.Text))
Gravar(txtLogin.Text, txtSenha.Text, txtNivel.Text**, txtInfAdicinais.Text);
else
MessageBox.Show("Ocorreu um erro");
}
}
Dice:
//Usuarios
public class Usuarios
{
public int IdUsuario { get; set; }
public string Login { get; set; }
public string Senha { get; set; }
public int Nivel { get; set; }
public string InfAdicionais { get; set; }
}
public void Gravar(string Login, string Senha, int Nivel, string InfAdicionais)
{
using (SqlConnection objConexao = new SqlConnection(strConexao))
{
using (SqlCommand objCommand = new SqlCommand(strInsert, objConexao))
{
objCommand.Parameters.AddWithValue("@Login", Login);
objCommand.Parameters.AddWithValue("@Senha", Senha);
objCommand.Parameters.AddWithValue("@Nivel", Nivel);
objCommand.Parameters.AddWithValue("@InfAdicionais", InfAdicionais);
objConexao.Open();
objCommand.ExecuteNonQuery();
objConexao.Close();
}
}
}
objCommand.Parameters.Addwithvalue("@Nivel", Nivel.Tostring());
– Marco Souza
Can you be a little more specific where I put this and why? I’m new to the subject
– Fernando Rodrigues
good ... Save(txtLogin.Text, txtSenha.Text, Int32.Parse( txtNivel.Text), txtInfAdicinais.Text);
– Marco Souza
https://answall.com/questions/212553/necessito-converter-uma-string-em-int-dentro-de-uma-hql
– Marco Souza
https://answall.com/questions/93866/converter-objeto-para-string/93870#93870
– Marco Souza