Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9242701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:38:09+00:00 2026-06-18T08:38:09+00:00

i am working on an application which will allow the user to add a

  • 0

i am working on an application which will allow the user to add a company via the form. i a struggling on inserting the data into the MySQL DB in the INSERT query. the query is sound as it will work when directly applied, however the application won’t commit…here is my code below…

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

           sqlconnection.Close()

Dim com As New MySqlCommand("INSERT INTO companies VALUES(company_id, '" & TextBox1.Text & "', '" & RichTextBox1.Text & "', '" & TextBox4.Text & "', '" & TextBox5.Text & "', '" & ComboBox6.Text & "', '" & TextBox2.Text & "', '" & TextBox7.Text & "', '" & TextBox3.Text & "', '" & ComboBox2.Text & "', '" & RichTextBox3.Text & "', '" & ComboBox5.Text & "', '" & RichTextBox2.Text & "', '" & ComboBox7.Text & "', '" & ComboBox1.Text & "', '" & ComboBox4.Text & "';", con)

        con.Open()

        com.ExecuteNonQuery()

        con.Close()

        MsgBox("committed")

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:38:10+00:00Added an answer on June 18, 2026 at 8:38 am

    That’s what you get for not using parametrized query.
    Probably in one or more of your textboxes or richtextboxes an apostrophe causes your string concatenation to confuse everything.
    Suppose that TextBox1 contains 'Acme's Inc.'. Now your string query text becomes

    INSERT INTO companies VALUES (company_id, 'Acme's Inc.', 
                                                   ^
    

    See the syntax error caused by blindly string concatenation?

    I can’t write a complete replacement of your code here because so many controls with undescriptive names. However you should write something like this

    Dim cmdText = "INSERT INTO companies VALUES (@companyID, @param1, @param2, ....etc")
    Dim com as New MySqlCommand(cmdText, con)
    com.Parameters.AddWithValue("@companyID", company_id)
    com.Parameters.AddWithValue("@param1", textbox1.Text)
    .... 'and so on'
    con.Open()
    com.ExecuteNonQuery()
    

    Apart from the quoting problem, correct representation of dates and decimal numbers for the underlying database system you have another big problem. SQL Injection (This is just an instructive link because SQL Injection is a very large topic)

    So at the end

    NEVER USE STRING CONCATENATION TO BUILD SQL QUERIES.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an application for iOS which will have the user fill out
I'm working on a web application which will take user input, display it and
I'm working on a product feature that will allow the user to export data
I'm working on a application which will export my DataGridView called scannerDataGridView to a
I have been working on a facebook application which will be using Graph API
I'm working on an iPhone application which will use long-polling to send event notifications
I am working on a web application (using Grails) which will generate a gift
I'm working on a project which will end up have a lot of application
I'm currently working on an oophp application. I have a site class which will
I am working on an application that will do some sort of smart data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.