I have a problem in bindear a gridview, since I need that when finishing the operations of a static method recharge the data of a gridview, place a breakpoint to know where the error was and it marks me when I assign the datatable to the datasource of the gridview
public static string GetDataAjax(int proyecto, int concepto,string descripcion, int cantidad, double precio, double subtotal, string fechaComprobante, string operacion, string sesion)
{
string mensajeOperacion="";
clCajaChica oProyectoGto = new clCajaChica();
EntidadProyectoGasto EntProyectoGto = new EntidadProyectoGasto();
EntProyectoGto.IDProyecto = Convert.ToInt32(proyecto);
EntProyectoGto.IDConceptoGasto = Convert.ToInt32(concepto);
EntProyectoGto.Descripcion = descripcion;
EntProyectoGto.Cantidad = Convert.ToInt32(cantidad);
EntProyectoGto.PrecioUnitario = Convert.ToDouble(precio);
EntProyectoGto.SubTotal = Convert.ToDouble(subtotal);
EntProyectoGto.FechaComprobante = Convert.ToDateTime(fechaComprobante);
EntProyectoGto.UrlArchivo = "x";
EntProyectoGto.IDUsuarioAlta = Convert.ToInt32(sesion);
EntProyectoGto.FechaAlta = Convert.ToDateTime(DateTime.Now);
EntProyectoGto.IDUsuarioModifica = Convert.ToInt32(sesion);
EntProyectoGto.FechaModifica = Convert.ToDateTime(DateTime.Now);
if (operacion == "Agregar")
{
if (oProyectoGto.InsertarProyectoGasto(EntProyectoGto) > 0)
{
ControlEscolar_CajaChica_DatosProyectosEfectivo instance = new ControlEscolar_CajaChica_DatosProyectosEfectivo();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("SELECT pg.ID_ProyectoGasto, pg.ID_Proyecto, p.tituloproyecto, pg.ID_ConceptoGasto, cg.conceptogasto, pg.Descripcion,pg.Cantidad,pg.PrecioUnitario,pg.SubTotal,pg.FechaComprobante, pg.UrlArchivo,pg.Validado,pg.Eliminado FROM ProyectosGastos pg INNER JOIN Proyectos p ON p.id_proyecto = pg.id_proyecto INNER JOIN ConceptosGastos cg ON cg.id_conceptogasto = pg.id_conceptogasto WHERE pg.id_proyecto = '" + proyecto + "' AND pg.Eliminado <> 1 ORDER BY pg.ID_ProyectoGasto DESC", con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
instance.GridView1.DataSource = dt;
instance.GridView1.DataBind();
}
mensajeOperacion = "ok";
}
else
{
mensajeOperacion = ("No se pudo agregar el registro.");
}
}
return mensajeOperacion;
}