Click here to Skip to main content
15,886,199 members
Home / Discussions / C#
   

C#

 
GeneralRe: Illegal characters in path. Pin
Vimalsoft(Pty) Ltd4-Aug-10 8:00
professionalVimalsoft(Pty) Ltd4-Aug-10 8:00 
AnswerRe: Illegal characters in path. Pin
DaveyM694-Aug-10 11:58
professionalDaveyM694-Aug-10 11:58 
QuestionBinding Source Issue Pin
spankyleo1234-Aug-10 2:59
spankyleo1234-Aug-10 2:59 
AnswerRe: Binding Source Issue Pin
Ennis Ray Lynch, Jr.4-Aug-10 5:02
Ennis Ray Lynch, Jr.4-Aug-10 5:02 
GeneralRe: Binding Source Issue Pin
spankyleo1234-Aug-10 5:23
spankyleo1234-Aug-10 5:23 
QuestionC#.NET 3.5 Excel 2007 Ribbon Add-in VS 2008 run macro Pin
Wheels0124-Aug-10 2:56
Wheels0124-Aug-10 2:56 
AnswerRe: C#.NET 3.5 Excel 2007 Ribbon Add-in VS 2008 run macro Pin
Wheels0124-Aug-10 8:18
Wheels0124-Aug-10 8:18 
QuestionSQL Query string issue Pin
MumbleB4-Aug-10 2:54
MumbleB4-Aug-10 2:54 
Hi Guys,

I am having troyble with a SQL query. When I run the same query in SQL Server management studio it works fine. When I try and pass it through C# string I get an error. I know it has to do with the sum(HoursWorked) portion of the query. What I want to do is the following. This is from SQL Server management studio:
SELECT TSPRojectCodeID, EmployeeID, sum(HoursWorked) AS "Total Hours"
FROM tblTimesheetDetails
WHERE TimeSheetDate >= '2010/07/01' AND TimeSheetDate <= '2010/07/30' 
GROUP BY TSProjectCodeID, EmployeeID;


When I try and pass the same query in C# i get and error that reads as follows:"The Select statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect."

The code used is as follows:
public string processSQL()
{
    string sql = null;
    string inSql = null;
    string firstPart = null;
    string lastPart = null;
    int selectStart = 0;
    int fromStart = 0;
    string[] fields = null;
    string[] sep = { "," };
    int i = 0;
    TextObject MyText;
    string startdate = fromDate.Value.ToString("yyyy/MM/dd");
    string todate = toDate.Value.ToString("yyyy/MM/dd");
    //inSql = @"Select EmployeeID,TSProjectCodeID,TaskCode,TimeSheetDate, from tblTimesheetDetails WHERE TimeSheetDate >= '" + startdate + "' AND TimeSheetDate <= '" + todate + "' AND TSProjectCodeID = '" + cmbprojects.Text.ToString() + "'";//ORDER BY TSProjectCode";
    inSql = @" Select DISTINCT TSProjectCodeID, EmployeeID, SUM(HoursWorked) AS 'Total_Hours', FROM tblTimesheetDetails WHERE TimeSheetDate >= '" + startdate + "' AND TimeSheetDate <= '" + todate + "' AND TSProjectCodeID = '" + cmbprojects.Text.ToString() + "'ORDER BY TSProjectCodeID, EmployeeID, HoursWorked";
    //inSql = textBox1.Text;
    inSql = inSql.ToUpper();

    selectStart = inSql.IndexOf("SELECT");
    fromStart = inSql.IndexOf("FROM");
    selectStart = selectStart + 15;
    firstPart = inSql.Substring(selectStart, (fromStart - selectStart));
    lastPart = inSql.Substring(fromStart, inSql.Length - fromStart);

    fields = firstPart.Split(',');
    firstPart = "";
    for (i = 0; i <= fields.Length - 1; i++)
    {
        if (i > 0)
        {
            firstPart = firstPart + ", " + fields[i].ToString() + " AS COLUMN" + (i + 1);
            firstPart.Trim();

            MyText = (TextObject)objRpt.ReportDefinition.ReportObjects[i];// + 1];
            MyText.Text = fields[i].ToString();
        }
        else
        {
            firstPart = firstPart + fields[i].ToString() + " AS COLUMN" + (i +1);// + 1);
            firstPart.Trim();

            MyText = (TextObject)objRpt.ReportDefinition.ReportObjects[i];// + 1];
            MyText.Text = fields[i].ToString();
        }
    }
    sql = "SELECT " + firstPart + " " + lastPart;
    return sql;
}


If you have any ideas or suggestions please let me know. I am about to give up on this!! Sigh | :sigh: Cry | :((
Excellence is doing ordinary things extraordinarily well.

AnswerRe: SQL Query string issue Pin
Eddy Vluggen4-Aug-10 3:02
professionalEddy Vluggen4-Aug-10 3:02 
AnswerRe: SQL Query string issue Pin
PIEBALDconsult4-Aug-10 3:10
mvePIEBALDconsult4-Aug-10 3:10 
GeneralRe: SQL Query string issue Pin
MumbleB4-Aug-10 4:35
MumbleB4-Aug-10 4:35 
GeneralRe: SQL Query string issue Pin
Eddy Vluggen4-Aug-10 10:12
professionalEddy Vluggen4-Aug-10 10:12 
GeneralRe: SQL Query string issue Pin
MumbleB4-Aug-10 11:27
MumbleB4-Aug-10 11:27 
GeneralRe: SQL Query string issue Pin
Eddy Vluggen5-Aug-10 0:26
professionalEddy Vluggen5-Aug-10 0:26 
GeneralRe: SQL Query string issue Pin
PIEBALDconsult4-Aug-10 15:39
mvePIEBALDconsult4-Aug-10 15:39 
GeneralRe: SQL Query string issue Pin
MumbleB4-Aug-10 11:30
MumbleB4-Aug-10 11:30 
GeneralRe: SQL Query string issue Pin
PIEBALDconsult4-Aug-10 15:37
mvePIEBALDconsult4-Aug-10 15:37 
GeneralRe: SQL Query string issue Pin
MumbleB10-Aug-10 6:28
MumbleB10-Aug-10 6:28 
GeneralRe: SQL Query string issue Pin
PIEBALDconsult10-Aug-10 14:39
mvePIEBALDconsult10-Aug-10 14:39 
QuestionSave DataGridView changes to database through multiple layers Pin
anthasaurus4-Aug-10 0:45
anthasaurus4-Aug-10 0:45 
AnswerRe: Save DataGridView changes to database through multiple layers Pin
Luc Pattyn4-Aug-10 1:45
sitebuilderLuc Pattyn4-Aug-10 1:45 
GeneralRe: Save DataGridView changes to database through multiple layers Pin
anthasaurus4-Aug-10 1:51
anthasaurus4-Aug-10 1:51 
QuestionWindows Form (C#.net) Pin
onecomputerguy4-Aug-10 0:36
onecomputerguy4-Aug-10 0:36 
AnswerRe: Windows Form (C#.net) Pin
OriginalGriff4-Aug-10 1:04
mveOriginalGriff4-Aug-10 1:04 
QuestionHello Sir i am muthu from kumbakonam Pin
Muthumca3-Aug-10 21:24
Muthumca3-Aug-10 21:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.