A new expression requires () or... in LINQ
This is driving me nuts.
I have the following code that, when a button is clicked, a gridview will be populated with data based on the number a client enters into a text box (tbxHowMany).
protected void btnDisplayTopReport_Click(object sender, EventArgs e)
{
if (radPa.Ch开发者_开发知识库ecked)
{
CompleteWeightsDataContext db = new CompleteWeightsDataContext
int max = 0;
if (int.TryParse(tbxHowMany.Text, out max))
{
var queryPa = db.tblOnlineReportingCOMPLETEWeights
.Where (x => x.MaterialLevel == "Primary" && x.MaterialText == "Paper")
.OrderByDescending (x => x.ProductPercentage).Take(max);
GridView1.DataSourceID = "queryPa";
GridView1.DataBind();
}
}
else if (radGl.Checked)
{
CompleteWeightsDataContext db = new CompleteWeightsDataContext
int max = 0;
if (int.TryParse(tbxHowMany.Text, out max))
{
var queryGl = db.tblOnlineReportingCOMPLETEWeights
.Where (x => x.MaterialLevel == "Primary" && x.MaterialText == "Glass")
.OrderByDescending (x => x.ProductPercentage).Take(max);
GridView1.DataSourceID = "queryGl";
GridView1.DataBind();
}
}
}
Unfortunately I keep on getting "a new expression requires (),[], etc" on the first int.
Can someone explain to me the error and/or what I have done wrong and how I can work around this?
Apologies for the, most likely dim, question.
Your error is actually on the line before (it shows up as on that line, because the line before isn't properly terminated, so int max...
is where the compiler first realizes something's gone wrong.
The error is here:
CompleteWeightsDataContext db = new CompleteWeightsDataContext
It should be:
CompleteWeightsDataContext db = new CompleteWeightsDataContext();
精彩评论