I have a SQL connection string like this:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
I have a query like this: stratdate = 10-03-2001, Enddate = 20-08-2008
string sql = string.Format(@"SELECT CONCAT(UPPER(SUBSTRING(visit_Status, 1, 1)), SUBSTRING(visit_Status FROM 2)) as Status, COUNT('x') AS Visits
FROM visits
WHERE visit_Date BETWEEN '{0}' AND '{1}'
GROUP BY visit_Status", StartDate.ToString(dateFormat), EndDate.ToString(dateFormat))
I don’t know how to pass this query to database with connection string and getting the results into datatable. I’m doing WinForms applications with C# and using MySQL as database.
How can I do this? Would anyone have any idea about this? How can I pass this as a command text to MySQL? Would anyone help me with a sample code snippet?
1 Answer