Home All Groups Group Topic Archive Search About

SqlCommand SQL statement 'stuck'

Author
13 Apr 2005 7:28 PM
KevinRug

In the code below, I am trying to change the select statment to be
"distinct" , ( i have also tried "top 1"), but when the code runs I always
get the original query "Select city from doctors".

Here is a code extract

    SqlCommand cmdCities = new SqlCommand("Select city from doctors",
sqlConnection1);
    SqlDataReader drCities;
    sqlConnection1.Open();
    drCities = cmdCities.ExecuteReader();
    lstCities.DataSource = drCities;
    lstCities.DataTextField = "City";
    lstCities.DataBind();
    drCities.Close();
    sqlConnection1.Close();




Any ideas as to why the query changes are not being accepted?

Kevin Ruggles

Author
13 Apr 2005 7:35 PM
Marina
I don't see any code trying to change the query.

Show quoteHide quote
"KevinRug" <kevin***@discussions.microsoft.com> wrote in message
news:OxqM97FQFHA.2932@TK2MSFTNGP09.phx.gbl...
> In the code below, I am trying to change the select statment to be
> "distinct" , ( i have also tried "top 1"), but when the code runs I always
> get the original query "Select city from doctors".
>
> Here is a code extract
>
>    SqlCommand cmdCities = new SqlCommand("Select city from doctors",
> sqlConnection1);
>    SqlDataReader drCities;
>    sqlConnection1.Open();
>    drCities = cmdCities.ExecuteReader();
>    lstCities.DataSource = drCities;
>    lstCities.DataTextField = "City";
>    lstCities.DataBind();
>    drCities.Close();
>    sqlConnection1.Close();
>
>
>
>
> Any ideas as to why the query changes are not being accepted?
>
> Kevin Ruggles
>
>
Are all your drivers up to date? click for free checkup

Author
13 Apr 2005 7:50 PM
KevinRug
I did not show all the code, but these are the 3 queries I have tried. They
all return the same result as the first query

Select city from doctors
Select top 1 city from doctors
Select distinct city from doctors

Show quoteHide quote
"Marina" <someone@nospam.com> wrote in message
news:utCik$FQFHA.2136@TK2MSFTNGP14.phx.gbl...
> I don't see any code trying to change the query.
>
> "KevinRug" <kevin***@discussions.microsoft.com> wrote in message
> news:OxqM97FQFHA.2932@TK2MSFTNGP09.phx.gbl...
> > In the code below, I am trying to change the select statment to be
> > "distinct" , ( i have also tried "top 1"), but when the code runs I
always
> > get the original query "Select city from doctors".
> >
> > Here is a code extract
> >
> >    SqlCommand cmdCities = new SqlCommand("Select city from doctors",
> > sqlConnection1);
> >    SqlDataReader drCities;
> >    sqlConnection1.Open();
> >    drCities = cmdCities.ExecuteReader();
> >    lstCities.DataSource = drCities;
> >    lstCities.DataTextField = "City";
> >    lstCities.DataBind();
> >    drCities.Close();
> >    sqlConnection1.Close();
> >
> >
> >
> >
> > Any ideas as to why the query changes are not being accepted?
> >
> > Kevin Ruggles
> >
> >
>
>
Author
13 Apr 2005 7:54 PM
Marina
Is this an asp.net project? Are you recompiling it before trying to load the
page again?

Show quoteHide quote
"KevinRug" <kevin***@discussions.microsoft.com> wrote in message
news:ukZ08HGQFHA.2580@TK2MSFTNGP10.phx.gbl...
>I did not show all the code, but these are the 3 queries I have tried. They
> all return the same result as the first query
>
> Select city from doctors
> Select top 1 city from doctors
> Select distinct city from doctors
>
> "Marina" <someone@nospam.com> wrote in message
> news:utCik$FQFHA.2136@TK2MSFTNGP14.phx.gbl...
>> I don't see any code trying to change the query.
>>
>> "KevinRug" <kevin***@discussions.microsoft.com> wrote in message
>> news:OxqM97FQFHA.2932@TK2MSFTNGP09.phx.gbl...
>> > In the code below, I am trying to change the select statment to be
>> > "distinct" , ( i have also tried "top 1"), but when the code runs I
> always
>> > get the original query "Select city from doctors".
>> >
>> > Here is a code extract
>> >
>> >    SqlCommand cmdCities = new SqlCommand("Select city from doctors",
>> > sqlConnection1);
>> >    SqlDataReader drCities;
>> >    sqlConnection1.Open();
>> >    drCities = cmdCities.ExecuteReader();
>> >    lstCities.DataSource = drCities;
>> >    lstCities.DataTextField = "City";
>> >    lstCities.DataBind();
>> >    drCities.Close();
>> >    sqlConnection1.Close();
>> >
>> >
>> >
>> >
>> > Any ideas as to why the query changes are not being accepted?
>> >
>> > Kevin Ruggles
>> >
>> >
>>
>>
>
>
Author
13 Apr 2005 7:49 PM
Alex Passos
SELECT distinct city from doctors.

Try it.

Alex

Show quoteHide quote
"KevinRug" <kevin***@discussions.microsoft.com> wrote in message
news:OxqM97FQFHA.2932@TK2MSFTNGP09.phx.gbl...
> In the code below, I am trying to change the select statment to be
> "distinct" , ( i have also tried "top 1"), but when the code runs I always
> get the original query "Select city from doctors".
>
> Here is a code extract
>
>    SqlCommand cmdCities = new SqlCommand("Select city from doctors",
> sqlConnection1);
>    SqlDataReader drCities;
>    sqlConnection1.Open();
>    drCities = cmdCities.ExecuteReader();
>    lstCities.DataSource = drCities;
>    lstCities.DataTextField = "City";
>    lstCities.DataBind();
>    drCities.Close();
>    sqlConnection1.Close();
>
>
>
>
> Any ideas as to why the query changes are not being accepted?
>
> Kevin Ruggles
>
>
Author
13 Apr 2005 11:45 PM
KevinRug
ok, whack me with a stick,

I found out the control, dropdownlistbox, was databound to a dataset, and it
was not looking at the query.
I removed the data binding and viola it works :)

thanks to all

kevin


Show quoteHide quote
"KevinRug" <kevin***@discussions.microsoft.com> wrote in message
news:OxqM97FQFHA.2932@TK2MSFTNGP09.phx.gbl...
> In the code below, I am trying to change the select statment to be
> "distinct" , ( i have also tried "top 1"), but when the code runs I always
> get the original query "Select city from doctors".
>
> Here is a code extract
>
>     SqlCommand cmdCities = new SqlCommand("Select city from doctors",
> sqlConnection1);
>     SqlDataReader drCities;
>     sqlConnection1.Open();
>     drCities = cmdCities.ExecuteReader();
>     lstCities.DataSource = drCities;
>     lstCities.DataTextField = "City";
>     lstCities.DataBind();
>     drCities.Close();
>     sqlConnection1.Close();
>
>
>
>
> Any ideas as to why the query changes are not being accepted?
>
> Kevin Ruggles
>
>

Bookmark and Share