Jump to content

What's wrong with this INSERT INTO statement?


Recommended Posts

INSERT INTO Local_EPM_RETAIL 
('AK',2001,1,23128.65,206108.43,11.22,20214.1,208499.68,9.7,6260.39,88762.7,7.05,2360.91,17664.85,13.36,51964.04,521035.66,9.97,'F');

 

I'm converting a VB.NET program into C#. The problem is it deals with SQL and Databases, and I have never really worked with them before. I'm haphazardly stepping through this shoddily written VB program with no documentation while trying to find C# equivalents of commands in VB.NET That I've never seen before.

 

I've gotten through most of it, however; but one problem still plagues me. Whenever the program issues the

ADODB.Connection.Execute(SQL, out objout, -1)

command, (SQL Being the string "INSERT INTO Local_EPM_RETAIL

('AK',2001,1,23128.65,206108.43,11.22,20214.1,208499.68,9.7,6260.39,88762.7,7.05,2360.91,17664.85,13.36,51964.04,521035.66,9.97,'F');"), it gives me a Syntax error.

 

SyntaxError.jpg

 

I honestly don't know anything about what it's outputting, where it goes, what the table structure is, or anything at all really. All I know is, I was given this code, and I'm trying my best to fix it. If you could please help me, I would really appreciate it.

Wow, of course. That helped quite a bit! The program runs through a few INSERT INTO commands, but now it stops at this command:

 

INSERT INTO Local_EPM_RETAIL 
VALUES('WY',2002,12,14832.97,220509.09,6.73,14717.68,262221.95,5.61,22155.57,621151.58,3.57,698.98,11148.68,6.27,52405.19,1115031.3,4.7,'F');
Works /\

Does NOT Work \/
INSERT INTO Local_EPM_RETAIL 
VALUES('AK',2003,1,24685.92,216630.13,11.4,22817.73,228658.18,9.98,7281.32,95592.2,7.62,,,,54784.97,540880.5,10.13,'F');

 

Could it be because of all the Commas, it errors?

Hmm. Try adding 'NULL' to the values that don't have a value:

INSERT INTO Local_EPM_RETAIL 
VALUES('AK',2003,1,24685.92,216630.13,11.4,22817.73,228658.18,9.98,7281.32,95592.2,7.62,NULL,NULL,NULL,54784.97,540880.5,10.13,'F');

 

Of course, it might be that these fields have had the 'NOT NULL' attribute added to them.

Doh. Looking back at the original code, there is a line that says

emptystring="NULL"

 

In my naive coding wisdom, I copied instead:

emptystring=null

 

Thanks a lot for your help conker87, you just did in 5 minutes what I worked on for 5 hours yesterday! (Literally... =/)

 

Pretty Helpful People, indeed. :-D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.