|
Subject:
|
How to insert a value into database?
|
|
Posted By:
|
amit_mande@yahoo.com
|
Post Date:
|
9/12/2006 6:52:12 AM
|
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.
|
|
Reply By:
|
SriRamaKrishna
|
Reply Date:
|
9/12/2006 7:06:40 AM
|
At least let us know what is the error message in thrown exception
|
|
Reply By:
|
dparsons
|
Reply Date:
|
9/12/2006 7:08:17 AM
|
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."
|
|
Reply By:
|
amit_mande@yahoo.com
|
Reply Date:
|
9/12/2006 12:42:10 PM
|
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.
|
|
Reply By:
|
dparsons
|
Reply Date:
|
9/12/2006 1:34:33 PM
|
Dont double post.
INSERT INTO login(userID, password) VALUES('" & txt1.text & "','" & txt2.text &"')"
"The one language all programmers understand is profanity."
|
|
Reply By:
|
amit_mande@yahoo.com
|
Reply Date:
|
9/13/2006 10:41:39 AM
|
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
|
|
Reply By:
|
dparsons
|
Reply Date:
|
9/13/2006 12:13:50 PM
|
What is the error message?
"The one language all programmers understand is profanity."
|
|
Reply By:
|
amit_mande@yahoo.com
|
Reply Date:
|
9/14/2006 3:06:04 AM
|
This is error message
"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"
|
|
Reply By:
|
dparsons
|
Reply Date:
|
9/14/2006 12:24:24 PM
|
What line, what was the stack trace, etc etc etc??
"The one language all programmers understand is profanity."
|
|
Reply By:
|
amit_mande@yahoo.com
|
Reply Date:
|
9/19/2006 8:57:05 AM
|
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
|
|
Reply By:
|
gbianchi
|
Reply Date:
|
9/19/2006 9:04:57 AM
|
hi there.. if userid and password are string (or char) types shouldn't be surrounded by ' ?????
i mean...
"insert into login (UserId, Password) values ('@UserId', '@Password')"
HTH
Gonzalo
|
|
Reply By:
|
amit_mande@yahoo.com
|
Reply Date:
|
9/19/2006 12:46:11 PM
|
No no,Values of userid and password r taken from textboxes txtUserName.text and txtPassword.text
|
|
Reply By:
|
gbianchi
|
Reply Date:
|
9/19/2006 1:04:36 PM
|
again..
char values should be between ' when you pass it in a query... it doesn't matter how you build the query...
HTH
Gonzalo
|
|
Reply By:
|
dparsons
|
Reply Date:
|
9/21/2006 10:38:23 AM
|
quote: Originally posted by gbianchi
again..
char values should be between ' when you pass it in a query... it doesn't matter how you build the query...
HTH
Gonzalo
yes, agreed.
--Stole this from a moderator
I will only tell you how to do it, not do it for you. Unless, of course, you want to hire me to do work for you.
|