SQL Insert Into statement Syntax Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lars131
    New Member
    • Jul 2010
    • 5

    #1

    SQL Insert Into statement Syntax Error

    I'm working on a simple form to database program but I keep encountering a syntax error with my SQL statement.

    Since it's so long, I don't want to parameterize it, but I will if it's the only way...please don't suggest that first.

    Code:
    String strSQL = "INSERT INTO Grant (CFDAnum,ProgramTitle,DueDate,SubmitDate,Developer,Dept,ContactName,Phone,Email,AwardAmount,Match(Y/N),FundingType,FedGrantnum," +
                "PassThru,GrantContactName,GrantPhone,GrantEmail,ImmediateGrantorAgency,AgencyContactName,AgencyContactPhone,AgencyContactEmail,NoticeofAwardDate,FYFunding, " +
                "TermofAgreementDate,ExpirationDate,FSR1Due,FSR1Submit,FSR2Due,FSR2Submit,FSR3Due,FSR3Submit,FSR4Due,FSR4Submit,ReportingComplianceNotesandComments," +
                "FiscalOrderDeadline,CouncilApproval,GrantCode,GrantDetail,Budget,FundCode,IndexCode,RevenueSubobject,1stQtrBal,2ndQtrBal,3rdQtrBal,4thQtrBal,YearEnd,Comments) " +
                "VALUES('" + txtCFDA.Text + "','" + txtPrgrmTitle.Text + "','" + txtDueDate.Text + "','" + txtSubDate.Text + "','"
                    + txtDev.Text +"','" + txtDept.Text + "','" + txtContactName.Text + "','" + txtDeptPhone.Text + "','" + txtDeptEmail.Text + "','" + txtAwardAmt.Text +
                        "','" + txtMatch.Text + "','" + cboFundType.SelectedItem + "','" + txtFedGNum.Text + "','" + cboPassThru.SelectedItem + "','" + txtGrantContact.Text 
                        + "','" + txtGrantPhone.Text + "','" + txtGrantEmail.Text + "','" + txtImmGrant.Text + "','" + txtAgntCntctName.Text + "','" + txtAgntPhone.Text +
                        "','" + txtAgntEmail.Text + "','" + txtAwardDate.Text + "','" + txtFYFund.Text + "','" + txtAgreementDate.Text + "','" + txtExpireDate.Text
                        + "','" + txtFSR1.Text + "','" + txtFSR1Sub.Text + "','" + txtFSR2.Text + "','" + txtFSR2Sub.Text + "','" + txtFSR3.Text + "','" + txtFSR3Sub.Text
                        + "','" + txtFSR4.Text + "','" + txtFSR4Sub.Text + "','" + rtxReportComments.Text + "','" + txtFiscDead.Text + "','" + txtCouncApp.Text + "','"
                        + txtGrantCode.Text + "','" + txtGrantDetail.Text + "','" + txtBudget.Text + "','" + txtFundcode.Text + "','" + txtIndexCode.Text + "','"
                        + txtRevenue.Text + "','" + txt1stQtr.Text + "','" + txt2ndQtr.Text + "','" + txt3rdQtr.Text + "','" + txt4thQtr.Text + "','" + txtYearEnd.Text + "','" + rtxComments.Text + "');";

    Edit: I just tried placing [] around all column names, no success.
  • improvcornartist
    Recognized Expert Contributor
    • May 2007
    • 303

    #2
    Are you getting a specific syntax error?

    Comment

    • Lars131
      New Member
      • Jul 2010
      • 5

      #3
      Nope, it only supplies a "Syntax Error in INSERT INTO Statement" error message

      Comment

      • improvcornartist
        Recognized Expert Contributor
        • May 2007
        • 303

        #4
        If you print the completed strSQL, does it look okay? Any chance there is a type mismatch, such as trying to load text into an integer field, or a text value is too long for the database column?

        Comment

        • Lars131
          New Member
          • Jul 2010
          • 5

          #5
          Yea, I'm using numbers to test, but as you can see I have the ' 's to indicate text, all the columns are also text so there is no mismatch as far as I can tell.

          I'm also using 1 and 2 digit numbers

          Comment

          • improvcornartist
            Recognized Expert Contributor
            • May 2007
            • 303

            #6
            Does it work in smaller pieces? "Grant" may also be a keyword causing an error.

            Comment

            • Lars131
              New Member
              • Jul 2010
              • 5

              #7
              I thought about attempting it in smaller pieces, thats my next move.

              I saw a thread here from earlier where one of the suggestions was to query the database in access, im trying that now.

              Comment

              • Lars131
                New Member
                • Jul 2010
                • 5

                #8
                Bingo, turns out Grant must've been some keyword because its working now with grant in []

                thanks a ton

                Comment

                • improvcornartist
                  Recognized Expert Contributor
                  • May 2007
                  • 303

                  #9
                  Yeah, "grant" is used for giving privileges. Glad you got it working and that it turned out to be pretty simple.

                  Comment

                  Working...