 |
| 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
|
|
|
|

September 12th, 2006, 06:52 AM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

September 12th, 2006, 07:06 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
At least let us know what is the error message in thrown exception
|
|

September 12th, 2006, 07:08 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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."
|
|

September 12th, 2006, 12:42 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

September 12th, 2006, 01:34 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Dont double post.
INSERT INTO login(userID, password) VALUES('" & txt1.text & "','" & txt2.text &"')"
"The one language all programmers understand is profanity."
|
|

September 13th, 2006, 10:41 AM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

September 13th, 2006, 12:13 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
What is the error message?
"The one language all programmers understand is profanity."
|
|

September 14th, 2006, 03:06 AM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This is error message
"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"
|
|

September 14th, 2006, 12:24 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
What line, what was the stack trace, etc etc etc??
"The one language all programmers understand is profanity."
|
|

September 19th, 2006, 08:57 AM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |