How can I solve this problem of NullReferenceException was unhandled by user code, where I have a table inserted and it tells me that the value that returns to me is null?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
/// <summary>
///Clase Cliente
/// </summary>
public class clscliente: clsconexion
{
string tabla = "Clientes"; /
/
Nombre de mi tabla
protected string Nombre, Direccion, Telefono;
protected int idCliente;
public clscliente(int idCliente, string Nombre, string Direccion, string Telefono)
{
this.idcliente = idcliente;
this.Nombre = Nombre;
this.Direccion = Direccion;
this.Telefono = Telefono;
}
//metodos para establecer y recuperar datos
public int idcliente {
set { idCliente = value; }
get { return idCliente; }
}
public string nombre{
set { Nombre = value; }
get { return Nombre; }
}
public string direccion
{
set { Direccion = value; }
get { return Direccion; }
}
public string telefono
{
set { Telefono = value; }
get { return Telefono; }
}
//metodo agregar
public void agregar() {
conectar(tabla);
DataRow fila;
fila = Data.Tables["tabla"].NewRow();
fila["idCliente"] = idcliente;
fila["Nombre"] = Nombre;
fila["Direccion"] = Direccion;
fila["Telefono"] = Telefono;
Data.Tables[tabla].Rows.Add(fila);
AdaptadorDatos.Update(Data, tabla);
}
}