TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
56
1.8k
How to list aliased columns on reader
May 19 2016 12:20 PM
I'm trying to populate a chart and I need to grab data from an SQL Server database, I got my query and its quite simple but is made out of functions so the columns are all aliased, so when I try to add the columns to the reader I get no results, it just wont find them.
Here's my sample code...
public
static
List<Work> ListNaturalResources(
int
directorateId)
{
var newList =
new
List<CasesWorkType>();
using
(var connection =
new
SqlConnection(Settings.Default.ServicesConnectionString))
{
connection.Open();
string
sql =
"SELECT "
+
"MONTH(DateCreated) AS dMonth,"
+
"YEAR(DateCreated) AS dYear,"
+
"COUNT(*) AS dCount"
+
"FROM Works"
+
"WHERE DirectorateID = "
+ directorateId +
" "
+
"GROUP BY "
+
"MONTH(DateCreated), "
+
"YEAR(DateCreated);"
;
using
(var command =
new
SqlCommand(sql, connection))
{
using
(var reader = command.ExecuteReader())
{
while
(reader.Read())
{
var countPerDirectorate =
new
Work();
countPerDirectorate. ?????? = reader[
"WorkDescription"
].ToString();
newList.Add(countPerDirectorate);
}
}
}
}
return
newList;
}
Reply
Answers (
1
)
c# code for progress bar with % progress
Which will be efficient ? Inline query or store procedure...