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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:50:29+00:00 2026-06-14T20:50:29+00:00

Here is my code: Imports System.Data Imports System.Data.OleDb Public Class frmAdd Dim con As

  • 0

Here is my code:

Imports System.Data
Imports System.Data.OleDb

Public Class frmAdd
Dim con As New OleDbConnection
Dim com As New OleDbCommand
Dim ins As New OleDbCommand
Dim upd As New OleDbCommand
Dim strcon = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = Supplies.mdb")

Private Sub frmAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    con.ConnectionString = strcon
    con.Open()
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    ins.CommandText = "INSERT INTO [product info] ([Product Name:],[Description:],[Quantity:],[Type:],[Date Received:],[Barcode:],[Price:]) VALUES ('" & txtItemName.Text & "', '" & txtDescription.Text & "', " & txtItemCount.Text & ", '" & cmbItemType.Text & "', " & txtDate.Text & ", '" & txtBarcode.Text & "', '" & txtPrice.Text & "',);"
    ins.Parameters.AddWithValue("@name", txtItemName.Text)
    ins.Parameters.AddWithValue("@desc", txtDescription.Text)
    ins.Parameters.AddWithValue("@count", Convert.ToInt32(txtItemCount.Text))
    ins.Parameters.AddWithValue("@type", cmbItemType.Text)
    ins.Parameters.AddWithValue("@dt", Convert.ToDateTime(txtDate.Text))
    ins.Parameters.AddWithValue("@code", txtBarcode.Text)
    ins.Parameters.AddWithValue("@price", txtPrice.Text)

    ins.CommandType = CommandType.Text
    ins.Connection = con
    ins.ExecuteNonQuery()
    ins.Dispose()

    con.Close()

After I fill up all the textboxes, i hit the save button and when i hit the save button the error “Syntax error in INSERT INTO statement.”

  • 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-14T20:50:31+00:00Added an answer on June 14, 2026 at 8:50 pm

    Table names with spaces should be enclosed in square brackets (product info has space in its name), the same is true for column names (Product Name, Date Received).
    Then, if you really have a : in all of your columns name, then use everywhere the square brackets, otherwise remove the : from the sql text (and from the database fields).

    ins.CommandText = "INSERT INTO [product info] ([Product Name:], [Description:], " + 
                     "[Quantity:],[Type:],[Date Received:],[Barcode:],[Price:]) " + 
                     "VALUES (?,?,?,?,?,?,?)"
    

    Said that, never use string concatenation to build a sql text to pass to the database engine.
    You avoid problems with date and text parsing (for example, if one of your input text contains a quote, everything will fail) and moreover you avoid Sql Injection Attacks

    ins.Parameters.AddWithValue("@name", txtItemName.Text)
    ins.Parameters.AddWithValue("@desc", txtDescription.Text)
    ins.Parameters.AddWithValue("@count", Convert.ToInt32(txtItemCount.Text))
    ins.Parameters.AddWithValue("@type", cmbItemType.Text)
    ins.Parameters.AddWithValue("@dt", Convert.ToDateTime(txtDate.Text)
    ins.Parameters.AddWithValue("@code", txtBarcode.Text)
    ins.Parameters.AddWithValue("@price", Convert.ToDecimal(txtPrice.Text)
    

    I am assuming that Quantity is a numeric column, Date Received is a DateTime column and Price a numeric column.

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

Sidebar

Related Questions

I have the following code : Imports System.Data.OleDb Private Sub getData() Dim connStr As
here is my code:(get file line num and word count) import System.IO import Data.Maybe
Here is my code: import javax.swing.*; import java.awt.*; public class PanelModel { public static
Here is the code: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class TestGrid {
Here I found this code: import java.awt.*; import javax.swing.*; public class FunWithPanels extends JFrame
Here is a simple piece of code: import java.io.*; public class Read { public
Here users browse to the Excel file from there system and then data is
I have the following Haskell code import Data.Int import System.Environment type Coord = (Int16,
Here is the code: import javax.swing.SwingUtilities; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JLabel; import java.awt.event.*;
Here is my code import org.ksoap2.*; import org.ksoap2.serialization.*; import org.ksoap2.transport.*; import android.app.Activity; import android.os.Bundle;

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.