|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SQL Insert problemsHi
Using the old style of inserting data in a table str="Insert Into MyTable (Description, Test) Values ( 'The Quick, Black Jump's, Over The Lazy Dog', 'Test' )"; The above would fail since there are commas and single quote in the data. I thought fill(ing) a Dataset and the using update would overcome the problem, but it also has the same error, how does one solve such issues. TIA Barry barry <some***@somewhere.com> wrote:
> Using the old style of inserting data in a table It would fail an English grammar test too, but that's a different > > str="Insert Into MyTable (Description, Test) Values ( > 'The Quick, Black Jump's, Over The Lazy Dog', 'Test' > )"; > > The above would fail since there are commas and single quote in the data. matter ;) > I thought fill(ing) a Dataset and the using update would overcome the Use a parameterised SqlCommand instead of including the values in the > problem, but it also has the same error, how does one solve such issues. SQL statement itself. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet World class .NET training in the UK: http://iterativetraining.co.uk
Show quote
On Sat, 24 Nov 2007 14:17:08 +0530, "barry" <some***@somewhere.com> The single quote inside the first value causes a problem, but commaswrote: >Hi > >Using the old style of inserting data in a table > >str="Insert Into MyTable (Description, Test) Values ( > 'The Quick, Black Jump's, Over The Lazy Dog', 'Test' >)"; > >The above would fail since there are commas and single quote in the data. > >I thought fill(ing) a Dataset and the using update would overcome the >problem, but it also has the same error, how does one solve such issues. > >TIA >Barry do not. You have two choices. The easiest solution is to use parameters for the values. The other way is to use whatever method the database supports to enclose single quotes within a string. Often that is to double the quotes, but it might vary by type of backend. |
|||||||||||||||||||||||