473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

issue with datatable : Invalid column name ' : '

Hi,
I have a SQL stored procedure which looks like that:

SELECT @QuerySQL = 'SELECT [' + @LookupField + '] as LookupField,
G.GroupDesc + ' + '" : "' + ' + [' + @DescField + '] as DescField
FROM [' + @TableName + ']'
+ 'JOIN ItemGrouping IG on IG.CatID =' + cast(@CatID as varchar(50)) +
'and ItemID = [' + @LookupField + ']
JOIN [Grouping] G on G.GroupID = IG.GroupID
ORDER BY DescField'
EXEC @QuerySQL

Pretty tricky... but it works fine. The SQLServer Query Analyser
returns the expected records and the field DescField looks like :
somestring : someotherstring, so the concatenation works.

However, on the .Net side, when I do ExecuteNonQuery to fill my
Datatable, I get the following exception:

Invalid column name ' : '

I don't understand why it's trying to pick it up as a column, since
DescField should just be a varchar field made up of the concatenation
of @LookupField + ':' + @DescField

Any clue ?

Thanks

Jul 27 '06 #1
3 1992
IMO this is because you are using double quotes and depending on the quoted
identifier option double quotes are used to enclose a column name.

If you are using double quotes, try to use '' (two single quotes instead).
--
Patrice

"graphicsxp" <sa*************@googlemail.coma écrit dans le message de
news: 11*********************@i3g2000cwc.googlegroups.co m...
Hi,
I have a SQL stored procedure which looks like that:

SELECT @QuerySQL = 'SELECT [' + @LookupField + '] as LookupField,
G.GroupDesc + ' + '" : "' + ' + [' + @DescField + '] as DescField
FROM [' + @TableName + ']'
+ 'JOIN ItemGrouping IG on IG.CatID =' + cast(@CatID as varchar(50)) +
'and ItemID = [' + @LookupField + ']
JOIN [Grouping] G on G.GroupID = IG.GroupID
ORDER BY DescField'
EXEC @QuerySQL

Pretty tricky... but it works fine. The SQLServer Query Analyser
returns the expected records and the field DescField looks like :
somestring : someotherstring, so the concatenation works.

However, on the .Net side, when I do ExecuteNonQuery to fill my
Datatable, I get the following exception:

Invalid column name ' : '

I don't understand why it's trying to pick it up as a column, since
DescField should just be a varchar field made up of the concatenation
of @LookupField + ':' + @DescField

Any clue ?

Thanks

Jul 27 '06 #2
Hi Patrice,

Great ! Thank you so much. In fact I had to do triple quotes to avoid
SQL error syntax, but you put me on the right track.

Cheers
Sam
Patrice wrote:
IMO this is because you are using double quotes and depending on the quoted
identifier option double quotes are used to enclose a column name.

If you are using double quotes, try to use '' (two single quotes instead).
--
Patrice

"graphicsxp" <sa*************@googlemail.coma écrit dans le message de
news: 11*********************@i3g2000cwc.googlegroups.co m...
Hi,
I have a SQL stored procedure which looks like that:

SELECT @QuerySQL = 'SELECT [' + @LookupField + '] as LookupField,
G.GroupDesc + ' + '" : "' + ' + [' + @DescField + '] as DescField
FROM [' + @TableName + ']'
+ 'JOIN ItemGrouping IG on IG.CatID =' + cast(@CatID as varchar(50)) +
'and ItemID = [' + @LookupField + ']
JOIN [Grouping] G on G.GroupID = IG.GroupID
ORDER BY DescField'
EXEC @QuerySQL

Pretty tricky... but it works fine. The SQLServer Query Analyser
returns the expected records and the field DescField looks like :
somestring : someotherstring, so the concatenation works.

However, on the .Net side, when I do ExecuteNonQuery to fill my
Datatable, I get the following exception:

Invalid column name ' : '

I don't understand why it's trying to pick it up as a column, since
DescField should just be a varchar field made up of the concatenation
of @LookupField + ':' + @DescField

Any clue ?

Thanks
Jul 27 '06 #3
The external single quote is to start the string literal. Then you double
the single quote inside so that it is taken as a single quote embedded in a
literal string and not as the termination of this literal string.

--
Patrice

"graphicsxp" <sa*************@googlemail.coma écrit dans le message de
news: 11*********************@p79g2000cwp.googlegroups.c om...
Hi Patrice,

Great ! Thank you so much. In fact I had to do triple quotes to avoid
SQL error syntax, but you put me on the right track.

Cheers
Sam
Patrice wrote:
IMO this is because you are using double quotes and depending on the
quoted
identifier option double quotes are used to enclose a column name.

If you are using double quotes, try to use '' (two single quotes instead).
--
Patrice

"graphicsxp" <sa*************@googlemail.coma écrit dans le message de
news: 11*********************@i3g2000cwc.googlegroups.co m...
Hi,
I have a SQL stored procedure which looks like that:

SELECT @QuerySQL = 'SELECT [' + @LookupField + '] as LookupField,
G.GroupDesc + ' + '" : "' + ' + [' + @DescField + '] as DescField
FROM [' + @TableName + ']'
+ 'JOIN ItemGrouping IG on IG.CatID =' + cast(@CatID as varchar(50)) +
'and ItemID = [' + @LookupField + ']
JOIN [Grouping] G on G.GroupID = IG.GroupID
ORDER BY DescField'
EXEC @QuerySQL

Pretty tricky... but it works fine. The SQLServer Query Analyser
returns the expected records and the field DescField looks like :
somestring : someotherstring, so the concatenation works.

However, on the .Net side, when I do ExecuteNonQuery to fill my
Datatable, I get the following exception:

Invalid column name ' : '

I don't understand why it's trying to pick it up as a column, since
DescField should just be a varchar field made up of the concatenation
of @LookupField + ':' + @DescField

Any clue ?

Thanks

Jul 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: clyyy2002 | last post by:
At added two column and more column hereafter,I immediately click del button,the program is no problem. but if i first click the DataGrid columnHeader and then click the del button, i find when...
3
by: tomi | last post by:
Hi I have following problem. I have a datatable filled with some data. Each row holds its ID (column named "Row_ID") DataTable dtTable; I have a datagrid to which I assign this datatable....
1
by: Ersin Gençtürk | last post by:
I have 2 typed data tables inherited from the same dataset schema One called : table A with an identity column x column x is constrained to be unique. Other one is : table B with an identity...
3
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
0
by: Maart_newbie | last post by:
Hi all, I've got a question about returning the value of a pk-column to a DataTable after inserting a row (via a data-adapter) using MySql5. Here is the SQL and code concerned: ...
2
by: =?Utf-8?B?Sm9iIExvdA==?= | last post by:
How can I reconcile changes between two data table and create a subset of those changes. I have two data tables with same schema which gets populated from two different xml files. I want to get...
4
by: =?Utf-8?B?TWlrZSBE?= | last post by:
I read the CSV file into a DataTable. This is so I can fix invalid dates and other data I don't want in the database. Then I use SqlBulkCopy to insert the data into the SQL database. All the...
13
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I want to create a new column in a datatable from two existing columns. I have no problem to create the new column using the datatable.columns.add method. The problem is the value of the new...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.