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
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
15 Points
146 Posts
Alias Name and Datatable in C#
Dec 22, 2016 11:35 PM|Asp.net king|LINK
i use the following stored procedure in SQL :
I create a data table in visual studio and i got this error : Column 'x' does not belong to table .
the problem is the alias name x, the data table and SQL query is running well. Any help ?
(John Johnson)
All-Star
45489 Points
7008 Posts
Microsoft
Re: Alias Name and Datatable in C#
Dec 23, 2016 05:45 AM|Zhi Lv - MSFT|LINK
Hi asp.net King,
You can debug the columns property in datatable to find out what the column name is.
For example:
This is my store procedure:
The GetL() and Page_Load():
When I debug the Columns the result is:
You can see the column’s name is displayed
Best regards,
Dillion