Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 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 12th, 2006, 06:52 AM
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 How to insert a value into database?

I have problem with inserting values in database.
I got error at line myCommand.ExecuteNonQuery().That error is Oledb Exception.What are the possibilities of this error.

 
Old September 12th, 2006, 07:06 AM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

At least let us know what is the error message in thrown exception

 
Old September 12th, 2006, 07:08 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

There are about 2132231321 possiblities as to what that error could be caused from; try not to be so vauge. What is the error message, can we see some code, etc.

"The one language all programmers understand is profanity."
 
Old September 12th, 2006, 12:42 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

I have databse Crime.mdb at location d:\Ty256\Police-Crime\Crime.mdb.I have table named LogIn which has two fields UserId and Password.I want to create new record in this table by using Insert Query.This values are collected from two text boxes txt1(user name) & txt2(password) and insert them into LogIn table.This should be done on click of Add button.Connection should be opened and closed on click of Add.

 
Old September 12th, 2006, 01:34 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Dont double post.

INSERT INTO login(userID, password) VALUES('" & txt1.text & "','" & txt2.text &"')"

"The one language all programmers understand is profanity."
 
Old September 13th, 2006, 10:41 AM
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

I have following code that gives me error at this line
"myCommand.ExecuteNonQuer()".The error is Oledb Exception.What is wrong with this code.Give me right code.

Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\TYBSC\Police-Crime\Crime.mdb"
    Dim myAdapter As New OleDbDataAdapter
    Dim myDataSet As New DataSet
    Dim myConnection As OleDbConnection
    Dim myCommand As OleDbCommand
    Dim myDataView As New DataView

    Private Sub frmAdmin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        myConnection = New OleDbConnection(strConnection)
    End Sub

    Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
        myCommand = New OleDbCommand("INSERT INTO login(userID, password) VALUES('" & txtUserName.Text & "','" & txtPassword.Text & "')")
        myCommand.Connection = myConnection
        myConnection.Open()
        myCommand.ExecuteNonQuery()
        myConnection.Close()
    End Sub

 
Old September 13th, 2006, 12:13 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What is the error message?

"The one language all programmers understand is profanity."
 
Old September 14th, 2006, 03:06 AM
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

This is error message

"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"

 
Old September 14th, 2006, 12:24 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What line, what was the stack trace, etc etc etc??

"The one language all programmers understand is profanity."
 
Old September 19th, 2006, 08:57 AM
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

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert a value into database? [email protected] VB.NET 1 September 12th, 2006 01:35 PM
Can't insert into database chrscote Classic ASP Databases 1 June 15th, 2005 04:07 AM
Insert a record into a Database ersp Classic ASP Basics 3 May 9th, 2004 08:50 PM
How to insert new redord into a Database? ersp ASP.NET 1.x and 2.0 Application Design 1 May 9th, 2004 12:59 PM





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