Hi, Oops, accidentally posted this to the C# group so apologies for cross posting. VS2008 IDE Desktop app. Anybody out there deploying this db? I am finding a strange problem with column names. I am using an SQLCeCommand to create a datareader. I have a where clause that is refusing some of the column names. Saying the column name is not valid. The columns are visible in Server explorer. It seems to be column names that where added later on in the tables design. example of problem "select * from unit where parent_id = 1" //fails, parent_id was added after initial table construction "select * from unit where id = 1" //works id was part of table initial construction A third party Database console has no problem running the queries Code: SqlCeConnection conn = new SqlCeConnection(mstrConnectionString); //mstrConnection just has "DataSource = myFullPath\mydatabase.sdf conn.Open(); string sql = "select * from unit where parent_id = 1"; SqlCeCommand cmd = new SqlCeCommand(sql,conn); SqlCeDataReader r = cmd.ExecuteReader(); //DROPS DEAD HERE with 'invalid column' Appreciate any thoughts on the above. Thanks Bob
Are you sure the database at the location where you're looking does have that column name? Can you execute any command on that connection? If you execute the query select count(*) from information_schema.columns where column_name = 'parent_id', do you get something greater than 0? Ginny "bob" wrote in message news:4qhs04tiidd62cuuamse1fsq9dv2n14784@4ax.com... > Hi, > Oops, accidentally posted this to the C# group so apologies for cross > posting. > > VS2008 IDE Desktop app. > > Anybody out there deploying this db? > > I am finding a strange problem with column names. > > I am using an SQLCeCommand to create a datareader. > I have a where clause that is refusing some of the column names. > Saying the column name is not valid. > The columns are visible in Server explorer. > > It seems to be column names that where added later on in the tables > design. > example of problem > "select * from unit where parent_id = 1" //fails, parent_id was added > after initial table construction > > "select * from unit where id = 1" //works id was part of table > initial construction > > > A third party Database console has no problem running the queries > > Code: > > SqlCeConnection conn = new SqlCeConnection(mstrConnectionString); > //mstrConnection just has "DataSource = myFullPath\mydatabase.sdf > > conn.Open(); > string sql = "select * from unit where parent_id = 1"; > SqlCeCommand cmd = new SqlCeCommand(sql,conn); > SqlCeDataReader r = cmd.ExecuteReader(); //DROPS DEAD > HERE with 'invalid column' > > Appreciate any thoughts on the above. > > Thanks > Bob -- Ginny Caughey Device Application Development MVP www.wasteworks.com Software for Waste Management
Hi Ginny, Thanks for your reply. Given that no else has struck this problem I must be doing something wrong. Unfortunately I have moved the DAL back to Access. (Now targeting Framework 2.0 for the desktop version not because of this problem) When the app migrates onto a hand held I'll revisit the problem. regards Bob On Tue, 22 Apr 2008 17:12:31 -0400, "Ginny Caughey MVP" wrote: >Are you sure the database at the location where you're looking does have >that column name? Can you execute any command on that connection? If you >execute the query select count(*) from information_schema.columns where >column_name = 'parent_id', do you get something greater than 0? > >Ginny > >"bob" wrote in message >news:4qhs04tiidd62cuuamse1fsq9dv2n14784@4ax.com... >> Hi, >> Oops, accidentally posted this to the C# group so apologies for cross >> posting. >> >> VS2008 IDE Desktop app. >> >> Anybody out there deploying this db? >> >> I am finding a strange problem with column names. >> >> I am using an SQLCeCommand to create a datareader. >> I have a where clause that is refusing some of the column names. >> Saying the column name is not valid. >> The columns are visible in Server explorer. >> >> It seems to be column names that where added later on in the tables >> design. >> example of problem >> "select * from unit where parent_id = 1" //fails, parent_id was added >> after initial table construction >> >> "select * from unit where id = 1" //works id was part of table >> initial construction >> >> >> A third party Database console has no problem running the queries >> >> Code: >> >> SqlCeConnection conn = new SqlCeConnection(mstrConnectionString); >> //mstrConnection just has "DataSource = myFullPath\mydatabase.sdf >> >> conn.Open(); >> string sql = "select * from unit where parent_id = 1"; >> SqlCeCommand cmd = new SqlCeCommand(sql,conn); >> SqlCeDataReader r = cmd.ExecuteReader(); //DROPS DEAD >> HERE with 'invalid column' >> >> Appreciate any thoughts on the above. >> >> Thanks >> Bob
I don't know if you're using LINQ but I got burned by this once. I renamed the field in the context but the "Source" property was still pointing to the old column name. That caused my invalid column error. Tod "bob" wrote: > Hi, > Oops, accidentally posted this to the C# group so apologies for cross > posting. > > VS2008 IDE Desktop app. > > Anybody out there deploying this db? > > I am finding a strange problem with column names. > > I am using an SQLCeCommand to create a datareader. > I have a where clause that is refusing some of the column names. > Saying the column name is not valid. > The columns are visible in Server explorer. > > It seems to be column names that where added later on in the tables > design. > example of problem > "select * from unit where parent_id = 1" //fails, parent_id was added > after initial table construction > > "select * from unit where id = 1" //works id was part of table > initial construction > > > A third party Database console has no problem running the queries > > Code: > > SqlCeConnection conn = new SqlCeConnection(mstrConnectionString); > //mstrConnection just has "DataSource = myFullPath\mydatabase.sdf > > conn.Open(); > string sql = "select * from unit where parent_id = 1"; > SqlCeCommand cmd = new SqlCeCommand(sql,conn); > SqlCeDataReader r = cmd.ExecuteReader(); //DROPS DEAD > HERE with 'invalid column' > > Appreciate any thoughts on the above. > > Thanks > Bob >