Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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 September 19th, 2006, 12:50 PM
Authorized User
 
Join Date: Aug 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to amit_mande@yahoo.com Send a message via AIM to amit_mande@yahoo.com Send a message via MSN to amit_mande@yahoo.com Send a message via Yahoo to amit_mande@yahoo.com
Default What is wrong with following Insert Query?

This is my code

Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
        myCommand = New OleDbCommand

        myCommand.Connection = myConnection
        Dim intPositin As Int16
        intPositin = myCurrencyManager.Position

        myCommand.CommandText = "insert into login (UserId, Password) values (@UserId, @Password)"
        myCommand.Parameters.Add("@UserId", txtUserName.Text)
        myCommand.Parameters.Add("@Password", txtPassword.Text)
        myConnection.Open()
        Try
            myCommand.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
        myConnection.Close()
        FillDataSetAndView()
        BindFields()
        myCurrencyManager.Position = myCurrencyManager.Count
        ShowPosition()
        StatusBar1.Text = "Record Added"
        Clear()
    End Sub

I am using Try...Catch to catch exception.
I get Following exception

Syntax error in INSERT INTO statement

What is wrong with code.
if you have another code for inserting above values give me that code


 
Old September 19th, 2006, 04:41 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Just a wild guess... (I could be completely wrong about including the single quotes):
Code:
        myCommand.CommandText = "insert into login (UserId, Password) " & _
                                "values ('@UserId', '@Password')      "
        myCommand.Parameters.Add("@UserId", txtUserName.Text)
        myCommand.Parameters.Add("@Password", txtPassword.Text)
        myConnection.Open()
        But I hate parameters. I would use
Code:
        myCommand.CommandText = "insert into login (UserId, Password) " & _
                                " values ('" & txtUserName.Text & "', " & _
                                "         '" & txtPassword.Text & "'  " & _
                                "        )                            "
        myConnection.Open()





Similar Threads
Thread Thread Starter Forum Replies Last Post
What is wrong with this query?... rupen Access 5 April 30th, 2006 01:28 AM
What is wrong with this insert statement? method SQL Server 2000 13 April 27th, 2005 11:46 PM
What`s wrong with Query??? :( Varg_88 Classic ASP Basics 8 January 18th, 2005 09:41 AM
What is wrong with this Query? Section? xgbnow Pro VB Databases 3 February 9th, 2004 05:53 AM
SELECT and INSERT in wrong order sgarstin MySQL 0 October 16th, 2003 02:31 PM





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