Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Classic Visual Basic (VB 6 or earlier) » Database Programming » Insert Statment Error


Insert Statment ErrorExpand / Collapse
Author
Message
Posted 3/26/2010 4:45:56 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 3/26/2010 4:39:21 AM
Posts: 1, Visits: 2
[
Dim con As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\Users .... ") 'This here, declares where the database is located

Dim dt As New DataTable()
Dim str As String
Dim com As OleDb.OleDbCommand

Dim user_name As String = txtusername.Text
Dim pass_word As String = txtpassword.Text
'Dim application As String = txtapplication.Text

'try statement
Try
'declaration stage, declare all database components and strings

con.Open()

str = "insert into password(pass,username) values('" & pass_word & "','" & user_name & "')"

lblInfo.Text = "saved"

com = New Data.OleDb.OleDbCommand(str, con)
'execute the query
com.ExecuteNonQuery()
'close the connection
con.Close()

'if there is an error during the process ...
Catch ex As Exception
'warn the user that username is already taken
lblInfo.Text = "Username already exits. Please Try Another Username."

End Try
End Sub
/]


hi all, above is my code which is giving me some problems. actually im trying to insert into a MS ACCESS database, but for some reason im getting an error; Syntax error in INSERT INTO statement.

the thing is, when i paste the SQL statement into an SQL query it executes without any problems.

any help please?

please note im a bigginer

thanks
mark

ow yeah im a bigginer
Post #29059
Posted 3/26/2010 8:45:06 AM


Forum God

Forum God

Group: Moderators
Last Login: 2/5/2012 6:29:46 PM
Posts: 1,889, Visits: 5,254
Welcome to A1vbcode zulli-mlt.

It won't sort your problem but it will make your code stand out more professional. Please use Mark's Syntax.zip when posting VB code in here.

Keith

I've been programming with VB for 15 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Post #29063
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin, Mod, Mark, Keithuk

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 2:26pm