User-271186128 posted
Hi asp.net King,
Column 'x' does not belong to table .
You can debug the columns property in datatable to find out what the column name is.
For example:
This is my store procedure:
SELECT SUM(UnitPrice) as x from [Order Details] as cc
inner join Orders as c on c.OrderID=cc.OrderID
where CC.ProductID=@ProductID
The GetL() and Page_Load():
public DataTable GetL()
{
int id = 11;
SqlDataAdapter da = new SqlDataAdapter("OrderDetail", ConfigurationManager.ConnectionStrings["NorthwindConnectionString1"].ConnectionString);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.AddWithValue("@ProductID", id);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = GetL();
var a = dt.Rows[0]["x"].ToString();
var b = dt.Columns;
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
When I debug the Columns the result is:

You can see the column’s name is displayed
Best regards,
Dillion