Click here to Skip to main content
15,896,557 members

How to create an sql query including datetimepicker-values and present in charts C#

Handyman83 asked:

Open original thread
I am trying to program and mostly use the User Interface in design-time. So far, all has been well and I have only recently met a problem.

The thing is, that I know how to do this by writing the code and sql queries in the Form. Like i.e :

C#
sqlConnection con = new sqlConnection (conString);
//
// More code
//
for (int i = 1; i <= 12; i++)
{
    foreach (string row in ard.ardcruise)
    {
        bard.bardYear = ard.ardYear;
        bard.bardcruise_id = row.substring(0, row.IndexOf(" "));
    }

    SELECT ("cruise_id, DATEPART(dd, dt) As s_day, AVG(use) AS AVG_use FROM use" +
    "WHERE (cruise_id = " + bard.bardcruise_id + " AND use != 0 " + "AND DATEPART(mm, dt) = " + i.ToString() + " AND DATEPART(yyyy, dt) = " + bard.bardYear + " AND DATEPART(dd, dt) = " + d.ToString() + ") GROUP BY cruise_id, DATEPART(dd, dt) ORDER BY s_day", con);

    dscon.Clear();
    dacon.Fill(dscon, "AVG");


My question is.... How do I do the same in Design-time with User interface? How do I select month, year and day in DATEPART with dateTimePicker ?

In the end I would like to show AVG_use and s_day in a chart where cruise_id is Legend 1 or more depending on user selection.
I would like to write the sql statements in the query builder in visual studio 2010 professional

Thanks
Tags: C#, SQL, DateTime, Chart

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900