I have created a DataTable that I fill using a SQL query that has an ‘AS’ in it.
Example:
SELECT (tblUser.FirstName + ' ' + tblUser.LastName) AS 'UserFullName'
FROM tblUser
I use
SqlDataAdapter.Fill(dtblUserInfo)
to fill the table and have verified that the column UserFullName exists with a string of data inside.
I try and reference this cell with
string strUserFullName = dtblUserInfo.Rows[0]["UserFullName"].ToString();
and even though I can see that there is data in that cell by adding a watch, it returns an empty string.
I am sure that Row[0] is the row that has the cell with data in it and would not normally hard code this value but is just for explaination and debug purposes.
Any thoughts on this?
Thanks,
Steve.
Just replace this
by this
When you are using
ASyou don’t need the single quotes it’s expecting a new column name. Column names are never within quotes.If you want to replace the name with 2 words like User Full Name, you need use [], for example [UserFullName].