Incorrect syntax near '0'.

  • myCommand = New SqlCommand("insert into invoices ('" & RouteNumber & "','" & Route_date & "','" & txtStop.Text & "','" & txtCust.Text & "','" & txtInv.Text & "','" & txtamt.Text & "','" & txtVerify1.Text & "','" & txtveramt1.Text & "','" & txtVerify2.Text & "','" & txtveramt2.Text & "','" & txtVerify3.Text & "','" & txtveramt3.Text & "','" & txtVerify4.Text & "','" & txtveramt4.Text & "','N','0','0','0','0','0','0'", conn2)

    ra = myCommand.ExecuteNonQuery()

    mycommand.commandtext = "insert into invoices (' 113','8/23/2010','15','938886 ','6547852','1111.11','totes','3','cartons','3','hba','12','freez','15','N','0','0','0','0','0','0'"

    Anybody see the issue. i first started with no ticks around the 0's because didn't think number fields need ticks around them.

    Any help would be most appreicated

  • Where's your closing parentheses that should be near the last '0'?



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • I have it after the last 0 then a , anc then conn2)

  • I have ending ) after the , conn2). Tried putting it after the last '0'"), conn2 but it through up error about missing paren

  • tmurray 69699 (10/5/2010)


    I have it after the last 0 then a , anc then conn2)

    :blink:

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • tmurray 69699 (10/5/2010)


    I have ending ) after the , conn2). Tried putting it after the last '0'"), conn2 but it through up error about missing paren

    It's not in the text you posted.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • if you look at the set up of mycommand in the first part of my post I have ending paren after conn2.

    When I go into immediate window and print mycommand.commandtext it doesn't show the ending paren. If I put it after last '0'), conn2 I get a missing paren error.

  • tmurray 69699 (10/5/2010)


    if you look at the set up of mycommand in the first part of my post I have ending paren after conn2.

    When I go into immediate window and print mycommand.commandtext it doesn't show the ending paren. If I put it after last '0'), conn2 I get a missing paren error.

    have you tried '0')", conn2) ?



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • printing my command text looks good

    "insert into invoices (' 113','8/23/2010','5','938886 ','9632587','75326.21','Totes','8','cartons','4','cigs','8','hba','3','N','0','0','0','0','0','0')"

    but paste in sql manager and run query got me this

    Msg 103, Level 15, State 4, Line 1

    The identifier that starts with 'insert into invoices (' 113','8/23/2010','5','938886 ','9632587','75326.21','Totes','8','cartons','4','cigs','8','hba','3','N','' is too long. Maximum length is 128.

  • Shouldn't it be something like

    INSERT INTO INVOICES

    VALUES (xx,xx,xx,xx)

    There is no Values or Select in your statement...I've never tried without it but I would imagine that would throw an error.

  • Here is actual code in vb.net

    myCommand = New SqlCommand

    ("insert into invoices

    ('" & RouteNumber & "','" & Route_date & "','" & txtStop.Text & "','"

    & txtCust.Text & "','" & txtInv.Text & "','" &

    txtamt.Text & "','" & txtVerify1.Text & "','" & txtveramt1.Text & "'

    ,'" & txtVerify2.Text & "','" & txtveramt2.Text & "',

    '" & txtVerify3.Text & "','" & txtveramt3.Text & "',

    '" & txtVerify4.Text & "','" & txtveramt4.Text & "','N','0','0','0','0',

    '0','0')", conn2)

    ra = myCommand.ExecuteNonQuery()

  • Thanks... How I missed values is beyond me. Just goes to show that sometimes the second pair of eyes works when the obvious is missing

    Thanks

  • Derrick Smith (10/5/2010)


    Shouldn't it be something like

    INSERT INTO INVOICES

    VALUES (xx,xx,xx,xx)

    There is no Values or Select in your statement...I've never tried without it but I would imagine that would throw an error.

    Derrick, we don't need your help to look stupid. We can do that on our own! 😛

    Good catch and good example of how we sometimes overlook the simple stuff.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply