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 6017353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:06:59+00:00 2026-05-23T03:06:59+00:00

I am new to VB programming and have come across an problem:( after a

  • 0

I am new to VB programming and have come across an problem:( after a couple of days trying to resolve this need some help!

I am trying to pass some information from a VB form to my MySQL database. i have named all the textbox’s the same as the field in the database and checked all my database fields and textbox names which are all correct.

When i try to enter information into a form I sometimes get an error at the .executeNonQuery section of the code.

To test, I outputted the SQLStatement string to a textbox ( which pulled through all the fields from the textboxes correctly) then manually inputted the completed SQL query into the database and it worked. But when I try to do this in one go it seems to fail if there is too much text ( if i enter ‘a’ into each field it works). Are they limits to the size of the SQL query that can be passed from VB?? all the MySql database fields are set to text with no size limits.

Thanks in advance!!!

    Public Sub SaveQuote(ByRef SQLStatement As String)
    Dim cmd As MySqlCommand = New MySqlCommand

    With cmd
        .CommandText = SQLStatement
        .CommandType = CommandType.Text
        .Connection = SQLConnection
        .ExecuteNonQuery()
    End With
    SQLConnection.Close()
    MsgBox("successfully Added!")
    SQLConnection.Dispose()
End Sub

Private Sub CmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSave.Click

    Dim SQLstatement As String = "INSERT INTO laptopstock(forename,surname,emailaddress,contactnumber,quotedate,manufacturer,model,os,battery,drive,defects) VALUES('" & forename.Text & "','" & surname.Text & "','" & emailaddress.Text & "','" & contactnumber.Text & "', CURDATE(),'" & manufacturer.Text & "','" & modelnumber.Text & "','" & os.Text & "','" & batterycondition.Text & "','" & drivetype.Text & "','" & defects.Text & "')"
    SaveQuote(SQLstatement)
End Sub

‘Test SQL query

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


    Dim testSQLstatement As String = "INSERT INTO laptopstock(forename,surname,emailaddress,contactnumber,quotedate,manufacturer,model,os,battery,drive,defects) VALUES('" & forename.Text & "','" & surname.Text & "','" & emailaddress.Text & "','" & contactnumber.Text & "', CURDATE(),'" & manufacturer.Text & "','" & modelnumber.Text & "','" & os.Text & "','" & batterycondition.Text & "','" & drivetype.Text & "','" & defects.Text & "')"


    testbox.Text = testSQLstatement

End Sub

here is the output from testSQLstatement = testbox.text

    INSERT INTO laptopstock(forename,surname,emailaddress,contactnumber,quotedate,manufacturer,model,os,battery,drive,defects) VALUES('Joe','Bloggs','J.bloggs@jbloggs.com','07777777777', CURDATE(),'Sony','Vaio','Windows 7 Pro','Poor','DVD-Rom','Faulty Screen')

from what i can see it is correctly formatted and when i enter this directly into a query on the MySql server a record is created

  • 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-05-23T03:06:59+00:00Added an answer on May 23, 2026 at 3:06 am

    Does your application SQL login have insert rights on this table? Try executing a grant statment in SQL console directly:
    “grant insert on dbo.laptopstock to (add you application login here)”
    Also, I why are you passing the SQLStatement byref? You are not modifying it, so use byval. This shouldn’t impact the code, but is a good practice.

    I see you state that sometimes you get an error, so we can asume it is working code. That leads me to believe it is in your input data. Do the fields accept nulls? Are they the right format? Also, one of these things is not like the others, the date. You are passing the curdate() function in the insert. If the fields are all strings like you mention, then you are performing an implicit conversion from date to string. You could as easily built the insert string using the Vb.Net equivalent. (Date.Now.ToString).

    Lastly, it is hard to debug this without more detailed information about the
    error. As you have not posted code for your SQLConnection and MySLCommand objects (sure you don’t mean MySQLCommand as New SQLCommand) I have to assume they work.

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

Sidebar

Related Questions

I'm abit new to programming Android App's, however I have come across a problem,
I am new to programming, and have come across the following error: System.NullReferenceException was
I'm pretty new to iphone programming. I have come up with a problem when
I am just starting with OSGi programming and have come across two ways to
I have come across various situations, where I want to store some formatted data
This might come across as a simple question, but I have very limited experience
As a PHP programmer new to Perl working through 'Programming Perl', I have come
I am new to programming.I have seen this code.returning a derived class object to
I'm new to programming and I have the following problem. I have a navigation
We have 2 new GIS programmer/analyst in our department (new to programming and ArcObjects)

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.