Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6534481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:15:21+00:00 2026-05-25T10:15:21+00:00

I have a SQL connection string like this: Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword; I have

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:15:22+00:00Added an answer on May 25, 2026 at 10:15 am
    public DataTable GetVisits(System.DateTime startDate, System.DateTime endData)
    {
        const string SQL = "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 @startDate AND @endData GROUP BY visit_Status";
        const string CONNSTR = "Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;";
        var tblVisits = new DataTable("Visits");
        using (var conn = new MySql.Data.MySqlClient.MySqlConnection(CONNSTR)) {
            var cmd = new MySql.Data.MySqlClient.MySqlCommand(SQL, conn);
            var da = new MySql.Data.MySqlClient.MySqlDataAdapter(cmd);
            var param = new MySql.Data.MySqlClient.MySqlParameter("@startDate", MySql.Data.MySqlClient.MySqlDbType.Date);
            param.Direction = ParameterDirection.Input;
            param.Value = startDate;
            cmd.Parameters.Add(param);
            param = new MySql.Data.MySqlClient.MySqlParameter("@endDate", MySql.Data.MySqlClient.MySqlDbType.Date);
            param.Direction = ParameterDirection.Input;
            param.Value = endData;
            cmd.Parameters.Add(param);
            conn.Open();
            da.Fill(tblVisits);
        }
    
        return tblVisits;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have SQL data that looks like this: events id name capacity 1 Cooking
When using SQL Server Express 2005's User Instance feature with a connection string like
Hello we have an SQL server application running over a low bandwith connection. We
I have a connection to a Microsoft SQL Server and want the change the
Is there a connection limit on Sql Server 2005 Developers Edition. We have many
I have two SQL Server databases with identical schemas, but different data. I also
Is there any official write-up what forms can Data Source field take in sql
i have the following module and i would like to test connection. how do
I have an Access 2003 project in which all data is stored in SQL
We have a SQL Server 2005 database, and currently all our users are connecting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.