4
Good night! I am trying to perform a query in a mysql table, using English, and present this result in a gridview for the user. I have the table below:
I’m not searching all columns of this table, just a few for that I’m using the code below in my Manipulated class:
public GridView exibeCarteira(string cepf, GridView tb)
{
try
{
bancotccEntities bc = new bancotccEntities();
var crt = from cart in bc.carteira
where cart.cpf == cepf
select new
{
Código = cart.codigo,
Valor = cart.valoracao,
Quantidade = cart.qtdacao,
Total = cart.vtotalacao,
Investido = cart.vinvestido,
ValorTotal = cart.vtotalacao
};
tb.DataSource = crt;
tb.DataBind();
return tb;
}
catch (Exception e1)
{
throw new Exception(e1.Message.ToString());
}
}
this method is called by a method of another class the method is that:
public GridView mostraCarteira(string cpf, GridView gv)
{
try
{
ManipulaBanco mp = new ManipulaBanco();
return mp.exibeCarteira(cpf, gv);
}
catch (Exception e4)
{
throw new Exception(e4.Message.ToString());
}
}
To test this method I am using the Web class below:
public partial class ExibeCarteira : System.Web.UI.Page
{
string cpf;
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
exibirCarteira();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}
private void exibirCarteira()
{
try
{
Trataformes tf = new Trataformes();
this.gvcarteira = tf.mostraCarteira(cpf, gvcarteira);
}
catch (Exception e1)
{
throw new Exception(e1.Message.ToString());
}
}
protected void gvcarteira_SelectedIndexChanged(object sender, EventArgs e)
{
}}
When I compile I get the error below that I am unable to solve, someone can help me?
Data Binding directly to a store query (Dbset, Dbquery, Dbsqlquery, Dbrawsqlquery) is not supported. Instead populate a Dbset with data, for example by Calling Load on the Dbset, and then bind to local data. For WPF bind to Dbset.local. For Winforms bind to Dbset.local.Tobindinglist(). For ASP.NET Webforms you can bind to the result of Calling Tolist() on the query or use Model Binding, for more information see go.microsoft.com/fwlink/? Linkid=389592.
I do not know the mistake, if you have there to pass! something else
Código
with accentuation, it is not a good practice !!! and maybe it is the mistake!– user6026
Ops. Failed to pass error : Data Binding directly to a store query (Dbset, Dbquery, Dbsqlquery, Dbrawsqlquery) is not supported. Instead populate a Dbset with data, for example by Calling Load on the Dbset, and then bind to local data. For WPF bind to Dbset.local. For Winforms bind to Dbset.local.Tobindinglist(). For ASP.NET Webforms you can bind to the result of Calling Tolist() on the query or use Model Binding, for more information see http://go.microsoft.com/fwlink/? Linkid=389592.
– user9090
missed if give a Tolist() in crt, I put an answer!
– user6026