-2

This is the code, in SQL the columns ID_C and CALLE are int type, I am writing a C# app for add registry and the error is in the save button, in the int type textbox.

Someone help me!!

    private void btnGuardar_Click(object sender, EventArgs e)
    {
        Cliente Cliente = new Cliente();
        Cliente.ID_C = txtID.Text= Cliente.ID_C.ToString();
        Cliente.NOMBRES = txtNombres.Text;
        Cliente.CONTACTO = txtCorreo.Text;
        Cliente.CALLE = txtCalle.Text;
        Cliente.NUMERO = txtNumero.Text= Cliente.NUMERO.ToString();
        Cliente.COLONIA = txtColonia.Text;
        Cliente.FECHA_ALTA = txtFecha.Text;

        int resultado = ClienteDAL.Agregar(Cliente);

        if (resultado > 0)
        {
            MessageBox.Show("Datos guardados con exito", "Datos Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        else
        {
            MessageBox.Show("No se grabaron los datos", "Error al guardar", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

    }

    private void btnCerrar_Click(object sender, EventArgs e)
    {
        this.Close();
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Victor Hernandez
  • 175
  • 1
  • 2
  • 12

2 Answers2

0

Use it Like this:-

       Cliente.ID_C = Int32.Parse(txtID.Text);
       Cliente.CALLE = Int32.Parse(txtCalle.Text);
yash
  • 812
  • 3
  • 12
  • 37
  • thank u so much, but another error appear: sqlException was unhandled SqlConnection Conn = new SqlConnection("Data source=VICTOR-PC; Initial Catalog=KAZIIM; Integrated Security=True;"); Conn.Open(); – Victor Hernandez Nov 22 '14 at 07:41
  • can you give Exception Details?? @VictorHernandez – yash Nov 22 '14 at 07:56
  • the error say "Login failed for user ''." in System.data.sqlclient.sqlexcention... i use windows autentication and the error is in "conn.open();" line... error number 18456 – Victor Hernandez Nov 22 '14 at 08:07
  • Check Your Data Source Name and Database Name Again and try to Connect it using Sql server... – yash Nov 22 '14 at 08:10
  • the data source name and database name are corrects and the error continues – Victor Hernandez Nov 22 '14 at 08:15
  • Try this:-http://stackoverflow.com/questions/21180474/system-data-sqlclient-sqlexception-login-failed-for-user-xxx – yash Nov 22 '14 at 08:20
  • i tried but not working in my app, now the error is other: System.ArgumentException was unhandled HResult=-2147024809 Message=El formato de la cadena de inicialización no se ajusta a la especificación que comienza en el índice 73. Source=System.Data StackTrace: en System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) en – Victor Hernandez Nov 22 '14 at 08:56
0

You need to parse your string values into int:

Cliente.ID_C = Int32.Parse(txtID.Text);
Cliente.CALLE = Int32.Parse(txtCalle.Text);

To make it more robust, you can use TryParse instead.

Damir Arh
  • 17,637
  • 2
  • 45
  • 83
  • thank u so much, but another error appear: sqlException was unhandled: SqlConnection Conn = new SqlConnection("Data source=VICTOR-PC; Initial Catalog=KAZIIM; Integrated Security=True;"); Conn.Open(); – Victor Hernandez Nov 22 '14 at 07:46
  • @VictorHernandez Please, give more details about the unhandled SqlException. Also post it as another question. – Damir Arh Nov 22 '14 at 07:49
  • i cant post it in 90 minuts, the error say "Login failed for user ''." in System.data.sqlclient.sqlexcention... i use windows autentication and the error is in "conn.open();" line – Victor Hernandez Nov 22 '14 at 08:01