SQL statement working in SQL Server but not in .aspx.cs page

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default SQL statement working in SQL Server but not in .aspx.cs page

    I have written the following query with a subquery to add a counter to be
    added to a drop down list, which works in SQL Server,
    but when I transfer the statement into my .aspx page it doesn't.

    I keep on getting the error : Line 1: Incorrect syntax near ','.

    The SQL statement is :


    if (SqlConn.State == ConnectionState.Closed) SqlConn.Open();


    sqlString ="SELECT
    course_schedule.ScheduleID,coursename,startdate,en ddate,ctr FROM
    course_schedule," +

    "(SELECT count(*) as ctr,ScheduleID FROM TraineeCourses GROUP BY ScheduleID)
    ,courses " +

    "WHERE course_schedule.ScheduleID = TraineeCourses.ScheduleID AND
    course_schedule.CourseID = courses.CourseID";

    SqlCommand cmdGetCourses = new SqlCommand(sqlString,SqlConn);


    SqlDataReader readCourses = cmdGetCourses.ExecuteReader();

    while (readCourses.Read()) {

    ListItem NewItem = new ListItem();

    NewItem.Text = readCourses.GetString(1).ToString() + " : " +

    readCourses.GetDateTime(2).ToShortDateString() + " to " +

    readCourses.GetDateTime(3).ToShortDateString() + " : Places (" +

    readCourses.GetValue(4).ToString() + ")";

    NewItem.Value = readCourses.GetValue(0).ToString();

    this.drpCourses.Items.Add(NewItem);

    }

    readCourses.Close();

    And I cannot see where the problem lies. Can somebody help?

    Regards
    Garfield



    Garfield Guest

  2. Similar Questions and Discussions

    1. Accessing an .aspx page from server in a DMZ
      We are currently hosting our own web site; the web site of course resides outside the DMZ. For security reasons, the network crew will not allow us...
    2. Accessing a aspx page using HttpWebRequest from another aspx page on the same webapp
      Did you have any luck on this as I have the same problem. Maybe you can help me out of you solved your problem.
    3. Want to Reboot server from ASPX page
      I am developing a asp.net web based service application for our product I am trying to trigger a reboot of the server based on a user request I...
    4. Calling a html page from an asp page then returning to the next statement on the original asp page
      Hi! I have an ASP page that calls excel to create a report. This works fine. Now I need to call a html calendar page to filter what rows are...
    5. how to interact client script within aspx page to other page functions, etc.? PLEASE!!!
      Hi, I've spent all day trying to find some info on this...please help! I have an aspx page with an xmlDocument (not dataset/relational db) with...
  3. #2

    Default Re: SQL statement working in SQL Server but not in .aspx.cs page

    This is a classic asp newsgroup. While you may be lucky enough to find a
    dotnet-savvy person here who can answer your question, you can eliminate the
    luck factor by posting your question to an appropriate group. I suggest
    microsoft.public.dotnet.framework.adonet.



    Bob Barrows Guest

  4. #3

    Default Re: SQL statement working in SQL Server but not in .aspx.cs page

    SELECTcourse_schedule. are you missing a blank here or Am I blind.
    SELECT course_schedule.
    "Garfield" <gboodie@hotmail.com> wrote in message
    news:u2HZ8NDaDHA.2592@TK2MSFTNGP09.phx.gbl...
    > I have written the following query with a subquery to add a counter to be
    > added to a drop down list, which works in SQL Server, but when I transfer
    > the statement into my .aspx page it doesn't.
    >
    > I keep on getting the error : Line 1: Incorrect syntax near ','.
    >
    > The section of code with the SQL statement is :
    >
    > if (SqlConn.State == ConnectionState.Closed) SqlConn.Open();
    >
    > sqlString
    > ="SELECTcourse_schedule.ScheduleID,coursename,star tdate,enddate,ctr FROM
    > course_schedule," +
    > "(SELECT count(*) as ctr,ScheduleID FROM TraineeCourses GROUP BY
    ScheduleID)
    > ,courses " +
    > "WHERE course_schedule.ScheduleID = TraineeCourses.ScheduleID AND
    > course_schedule.CourseID = courses.CourseID";
    >
    > SqlCommand cmdGetCourses = new SqlCommand(sqlString,SqlConn);
    > SqlDataReader readCourses = cmdGetCourses.ExecuteReader();
    >
    > while (readCourses.Read())
    > {
    > ListItem NewItem = new ListItem();
    > NewItem.Text = readCourses.GetString(1).ToString() + " : " +
    >
    > readCourses.GetDateTime(2).ToShortDateString() + " to " +
    >
    > readCourses.GetDateTime(3).ToShortDateString() + " : Places (" +
    > readCourses.GetValue(4).ToString() + ")";
    >
    > NewItem.Value = readCourses.GetValue(0).ToString();
    > this.drpCourses.Items.Add(NewItem);
    > }
    > readCourses.Close();
    >
    >
    > And I cannot see where the problem lies. Can somebody help?
    >
    > Regards
    > Garfield
    >
    >
    >
    >

    MS News \(MS ILM\) Guest

  5. #4

    Default Re: SQL statement working in SQL Server but not in .aspx.cs page

    Shouldn't
    sqlString
    ="SELECTcourse_schedule.ScheduleID,coursename,star tdate,enddate,ctr FROM
    be
    sqlString
    ="SELECT course_schedule.ScheduleID,coursename,startdate,en ddate,ctr FROM

    Of course, if this was a SP, you would not have this problem... ;)
    --
    ____________________________________
    Bill Vaughn
    MVP, hRD
    [url]www.betav.com[/url]
    Please reply only to the newsgroup so that others can benefit.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    __________________________________

    "Garfield" <gboodie@hotmail.com> wrote in message
    news:u2HZ8NDaDHA.2592@TK2MSFTNGP09.phx.gbl...
    > I have written the following query with a subquery to add a counter to be
    > added to a drop down list, which works in SQL Server, but when I transfer
    > the statement into my .aspx page it doesn't.
    >
    > I keep on getting the error : Line 1: Incorrect syntax near ','.
    >
    > The section of code with the SQL statement is :
    >
    > if (SqlConn.State == ConnectionState.Closed) SqlConn.Open();
    >
    > sqlString
    > ="SELECTcourse_schedule.ScheduleID,coursename,star tdate,enddate,ctr FROM
    > course_schedule," +
    > "(SELECT count(*) as ctr,ScheduleID FROM TraineeCourses GROUP BY
    ScheduleID)
    > ,courses " +
    > "WHERE course_schedule.ScheduleID = TraineeCourses.ScheduleID AND
    > course_schedule.CourseID = courses.CourseID";
    >
    > SqlCommand cmdGetCourses = new SqlCommand(sqlString,SqlConn);
    > SqlDataReader readCourses = cmdGetCourses.ExecuteReader();
    >
    > while (readCourses.Read())
    > {
    > ListItem NewItem = new ListItem();
    > NewItem.Text = readCourses.GetString(1).ToString() + " : " +
    >
    > readCourses.GetDateTime(2).ToShortDateString() + " to " +
    >
    > readCourses.GetDateTime(3).ToShortDateString() + " : Places (" +
    > readCourses.GetValue(4).ToString() + ")";
    >
    > NewItem.Value = readCourses.GetValue(0).ToString();
    > this.drpCourses.Items.Add(NewItem);
    > }
    > readCourses.Close();
    >
    >
    > And I cannot see where the problem lies. Can somebody help?
    >
    > Regards
    > Garfield
    >
    >
    >
    >

    William \(Bill\) Vaughn Guest

  6. #5

    Default Re: SQL statement working in SQL Server but not in .aspx.cs page

    Thanks for your response. The query did work within
    SQL Server, but I don't know what happeened.

    I added a table Alais as suggested to my subquery
    and that solved my problem.

    Thanks

    Garfield



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Garfield Boodie Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139