Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 13th, 2005, 12:45 PM
Authorized User
 
Join Date: Jan 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default INSERT INTO error

Can someone tell me what is wrong with the code below? I am getting an error but I cannot see it. Thanks.

Imports System.Data
Imports System.Data.OleDb

Public Class frmReceived
    Inherits System.Windows.Forms.Form



Public Sub frmReceived_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Public Sub btnAddR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddR.Click
Dim myConnection As OleDbConnection = New _
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=G:\IDC\Received Dispensed Deleted.mdb;User Id=admin;Password=;")

        Dim myCommand As OleDbCommand = New OleDbCommand
        myCommand.Connection = myConnection
        myCommand.CommandText = "INSERT INTO Received" & _
        "(Received, Date)" & _
        "VALUES (@Received, @Date);"
        myCommand.Parameters.Add("@Received", TextBox1.Text)
        myCommand.Parameters.Add("@Date", Date.Now)
        myConnection.Open()
        Try
            myCommand.ExecuteNonQuery()
        Catch err As OleDbException
            MessageBox.Show(err.Message)
        Finally
            myConnection.Close()
        End Try

    End Sub
End Class
 
Old January 13th, 2005, 02:44 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I believe that your SQL should not have a terminating “;”.

That character is used to signify the end of a line/command/etc., but .CommandText will know where the line ends, and so the ‘;’ is unnecessary. (Anything unnecessary usually causes an error...)

[BTW: This question should probably be in Beginning VB.NET... Just a thought.]





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Insert Error FishBoy SQL Server ASP 2 April 7th, 2008 06:45 AM
Syntax error INSERT INTO ITladybug ADO.NET 2 January 31st, 2006 07:50 AM
HELP! Insert Query Error zrm22 Classic ASP Databases 1 January 30th, 2006 06:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.