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

  • Home
  • SEARCH
  • 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 6476197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:47:43+00:00 2026-05-25T06:47:43+00:00

I am getting a syntax error for the code below. I am trying to

  • 0

I am getting a syntax error for the code below.
I am trying to create a user in the mysql database and add their information to a datagrid control all in one button click using two statements; one to create the actual user, and one to add the user and their additional information to a table on the database and then refresh the datasource which will display the new user’s information in the datagrid control.
If anyone knows where i went wrong please feel free to critique my code and let me know; or simply offer more efficient alternatives to what im hoping to achieve.

For those of you that must know, i am running the latest version of MySql server, MySql Workbench, and Visual Basic 2010 Express on a windows 7 based laptop. I’m writing this program in VB.net.

Thanks!

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
    Dim sqluser As MySqlCommand = New MySqlCommand(
        "CREATE USER " & txtuser.Text & "@" & frmLogin.txtserver.Text & " IDENTIFIED BY '" & txtpass.Text & "';", con)
    Dim sqlinfo As MySqlCommand = New MySqlCommand(
        "INSERT INTO employee(Name ,Title) VALUES('" & txtname.Text & "','" & txttitle.Text & "';", con)
    Try
        con.Close()
        con.Open()

        sqluser.ExecuteNonQuery()
        MessageBox.Show("User Account successfully created!!")

        sqlinfo.ExecuteNonQuery()

        ' retrieving the administration table.
        DataAdapter1.SelectCommand = sqladmin
        DataAdapter1.Fill(ds, "stratos")
        DataGrid1.DataSource = ds
        DataGrid1.DataMember = "stratos"

        con.Close()
        MessageBox.Show("User Information successfully created!!")


    Catch myerror As MySqlException
        MessageBox.Show("Error Setting Up Account: " & myerror.Message)
    End Try

End Sub
  • 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-25T06:47:44+00:00Added an answer on May 25, 2026 at 6:47 am

    You are missing a ‘)’ at the end of your insert statement.

    Dim sqlinfo As MySqlCommand = New MySqlCommand("INSERT INTO employee(Name ,Title ) VALUES('" & txtname.Text & "','" & txttitle.Text & "');"
    

    I would also like to point out that this code will fail if the text has an apostrophe in it, and that it is wide open to SQL Injection. Please read up.

    I think you may also need apostrophes around the username and host.

    CREATE USER '" & txtuser.Text & "'@'" & frmLogin.txtserver.Text & "' IDENTIFIED BY '" & txtpass.Text & "';"
    

    As for SQL Injection, I would recommend you consider reworking your code to use prepared statements like this. Replace those first two lines with this instead. Basically, you put in little placeholders in your query, and let the database driver handle all of the complex escaping and quoting of things for you. I’m not 100% sure this will work, but I think it’s close.

    Dim sqluser As MySqlCommand = New MySqlCommand("CREATE USER ?user@?host IDENTIFIED BY ?pass;", con)
    sqluser.Parameters.Add("?user", txtuser.Text)
    sqluser.Parameters.Add("?host", frmLogin.txtserver.Text)
    sqluser.Parameters.Add("?pass", txtpass.Text)
    sqluser.Prepare()
    
    Dim sqlinfo As MySqlCommand = New MySqlCommand("INSERT INTO employee(Name ,Title) VALUES( ?user, ?title );", con)
    sqlinfo.Parameters.Add("?user", txtuser.Text)
    sqlinfo.Parameters.Add("?title", txttitle.Text)
    sqlinfo.Prepare()
    

    It has been ages since I did any VB, so this is mostly based on this page. Try to look here if this doesn’t quite work. Documentation on Prepare

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

Sidebar

Related Questions

I'm getting the following error on the line of code below: Syntax error (missing
I'm trying to achieve what the code below suggests, but I'm getting the error
THE CODE BELOW IS UPDATED CODE THAT WORKS I am getting a syntax error
I keep getting this error for the below MySQL SP any ideas? CREATE PROCEDURE
I'm getting the below error on my server: Parse error: syntax error, unexpected T_STRING,
Hi I'm using the following code but I'm getting an unexpected T_FUNCTION syntax error
I am getting this error when I try to run this MySQL command: CREATE
I'm trying to use the below code to bring back all records that are
I am placing a code below, I have created a local Thread and getting
I am getting this error when I use this code sub search { my

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.