Insert record from c # to sql send TextBox1 nullReference

0

I need to know why my code does not work, on previous occasions it worked perfectly but when creating a new project I was sent an error that I do not understand because it happens

the code of the function is the following:

 public void insertarCliente(String ide, String nom, String tel, String direc, String correo, String fech) {
        try
        {
            cn.conectarBase();
            comando.Connection = cn.getCon();

            SqlCommand insercion = new SqlCommand("insert into CLIENTES (Identificacion,NombreCliente,Telefono,Direccion,Correo,FechaRegistro) "
                + "values (@ide,@nom,@tel,@direc,@correo,@fech)", cn.getCon());

            odataAdapter.InsertCommand = insercion;
            odataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@ide", SqlDbType.NVarChar));
            odataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@nom", SqlDbType.NVarChar));
            odataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@tel", SqlDbType.NChar));
            odataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@direc", SqlDbType.NVarChar));
            odataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@correo", SqlDbType.NVarChar));
            odataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@fech", SqlDbType.NVarChar));

        }
        catch (SqlException e) { }
        finally { cn.desconectar(); }
    }

and when I call the procedure

private void button2_Click(object sender, EventArgs e)
    {
        if (textBox2.Text.Equals("") || textBox3.Text.Equals("") || textBox4.Text.Equals("") || textBox5.Text.Equals(""))
        {
            MessageBox.Show("Faltan datos por Completar");
        }
        else
        {
            m.insertarCliente(textBox1.Text,textBox2.Text,textBox3.Text,textBox4.Text,textBox5.Text,textBox6.Text);

            m.odataAdapter.InsertCommand.Parameters["@ide"].Value = textBox1;
            m.odataAdapter.InsertCommand.Parameters["@nom"].Value = textBox2;
            m.odataAdapter.InsertCommand.Parameters["@tel"].Value = textBox3;
            m.odataAdapter.InsertCommand.Parameters["@direc"].Value = textBox4;
            m.odataAdapter.InsertCommand.Parameters["@correo"].Value = textBox5;
            m.odataAdapter.InsertCommand.Parameters["@fech"].Value = textBox6;

            m.cn.conectarBase();
            int result = m.odataAdapter.InsertCommand.ExecuteNonQuery();
            m.cn.desconectar();
            MessageBox.Show("Cliente Agregado Correctamente");
            limpiar();
            bloquear();

        }
    }

but when I hit the button I get the error of

 Referencia a objeto no establecida como instancia de un objeto. 

but if the object exists and before that procedure I use it

    
asked by Daylight Ark 16.05.2017 в 21:31
source

0 answers