Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/03/2011, 22:45
Avatar de GzaPro
GzaPro
 
Fecha de Ingreso: marzo-2011
Ubicación: San Nicolas de los Arroyos
Mensajes: 5
Antigüedad: 13 años, 1 mes
Puntos: 0
Error ABM C# "Referencia al objeto no establecida como instancia de un objeto"

Hola Gente, me presento. Soy Gonzalo, nuevo por aquí me registré debido a que tengo un problema y no se como solucionarlo. Llegué a la conclusión de que estoy viviendo en un mundo paralelo al real donde nada tiene solución.

En fin llendo al grano, estoy haciendo un ABM con un punto de venta. Esta todo perfecto hasta el momento en que trato de guardar un Cliente en la base de datos.

Lenguaje: C#.NET
Base de datos: SQL

Este es el código de mi clase Cientes:

Código C:
Ver original
  1. namespace abm
  2. {
  3.     class clientes
  4.     {
  5.         public void AgregarCliente(string xnombre, string xapellido, string xcuit, string xdireccion, int xid_localidad, string xtelefono, string xcelular, string xemail, DateTime xfecha)
  6.         {
  7.             /*METODO AGREGAR CLIENTE*/
  8.             conexion cnn = new conexion();
  9.             SqlConnection cn = new SqlConnection(cnn.LeerConexion());
  10.             SqlCommand cmd = new SqlCommand("sp_insertarcliente", cn);
  11.             cmd.CommandType = CommandType.StoredProcedure;
  12.             cmd.Parameters.AddWithValue("@nombre",xnombre);
  13.             cmd.Parameters.AddWithValue("@apellido",xapellido);
  14.             cmd.Parameters.AddWithValue("@cuit",xcuit);
  15.             cmd.Parameters.AddWithValue("@direccion",xdireccion);
  16.             cmd.Parameters.AddWithValue("@id_localidad",xid_localidad);
  17.             cmd.Parameters.AddWithValue("@telefono",xtelefono);
  18.             cmd.Parameters.AddWithValue("@celular",xcelular);
  19.             cmd.Parameters.AddWithValue("@email",xemail);
  20.             cmd.Parameters.AddWithValue("@fecha",xfecha);
  21.             try
  22.             {
  23.                 cn.Open();
  24.                 cmd.ExecuteNonQuery();
  25.             }
  26.             catch (Exception ex)
  27.             {
  28.                 throw new Exception(ex.Message);
  29.             }
  30.             finally
  31.             {
  32.                 cn.Dispose();
  33.                 cmd.Dispose();
  34.             }
  35.         }
  36.  
  37.         /*METODO MODIFICAR CLIENTE*/
  38.         public void ModificarCliente(int xid_cliente, string xnombre, string xapellido, string xcuit, string xdireccion, int xid_localidad, string xtelefono, string xcelular, string xemail, DateTime xfecha)
  39.         {
  40.             conexion cnn = new conexion();
  41.             SqlConnection cn = new SqlConnection(cnn.LeerConexion());
  42.             SqlCommand cmd = new SqlCommand("sp_modificarcliente", cn);
  43.             cmd.CommandType = CommandType.StoredProcedure;
  44.             cmd.Parameters.AddWithValue("@id_cliente", xid_cliente);
  45.             cmd.Parameters.AddWithValue("@nombre", xnombre);
  46.             cmd.Parameters.AddWithValue("@apellido", xapellido);
  47.             cmd.Parameters.AddWithValue("@cuit", xcuit);
  48.             cmd.Parameters.AddWithValue("@direccion", xdireccion);
  49.             cmd.Parameters.AddWithValue("@id_localidad", xid_localidad);
  50.             cmd.Parameters.AddWithValue("@telefono", xtelefono);
  51.             cmd.Parameters.AddWithValue("@celular", xcelular);
  52.             cmd.Parameters.AddWithValue("@email", xemail);
  53.             cmd.Parameters.AddWithValue("@fecha", xfecha);
  54.             try
  55.             {
  56.                 cn.Open();
  57.                 cmd.ExecuteNonQuery();
  58.             }
  59.             catch (Exception ex)
  60.             {
  61.                 throw new Exception(ex.Message);
  62.             }
  63.             finally
  64.             {
  65.                 cn.Dispose();
  66.                 cmd.Dispose();
  67.             }
  68.         }
  69.         public void EliminarCliente(int xid_cliente)
  70.         {
  71.             conexion cnn = new conexion();
  72.             SqlConnection cn = new SqlConnection(cnn.LeerConexion());
  73.             SqlCommand cmd = new SqlCommand("sp_eliminarcliente", cn);
  74.             cmd.CommandType = CommandType.StoredProcedure;
  75.             cmd.Parameters.AddWithValue("@id_cliente", xid_cliente);
  76.             try
  77.             {
  78.                 cn.Open();
  79.                 cmd.ExecuteNonQuery();
  80.             }
  81.             catch (Exception ex)
  82.             {
  83.                 throw new Exception(ex.Message);
  84.             }
  85.             finally
  86.             {
  87.                 cn.Dispose();
  88.                 cmd.Dispose();
  89.             }
  90.         }
  91.  
  92.         public DataTable ListarCliente()
  93.         {
  94.             conexion cnn = new conexion();
  95.             SqlConnection cn = new SqlConnection(cnn.LeerConexion());
  96.             SqlCommand cmd = new SqlCommand("sp_listarcliente", cn);
  97.             cmd.CommandType = CommandType.StoredProcedure;
  98.             try
  99.             {
  100.                 SqlDataAdapter da = new SqlDataAdapter(cmd);
  101.                 DataTable tb = new DataTable();
  102.                 da.Fill(tb);
  103.                 return (tb);
  104.             }
  105.             catch (Exception ex)
  106.             {
  107.                 throw new Exception(ex.Message);
  108.             }
  109.             finally
  110.             {
  111.                 cn.Dispose();
  112.                 cmd.Dispose();
  113.             }
  114.         }
  115.        
  116.                                
  117.        }
  118.     }