|
-
Apr 4th, 2008, 02:55 AM
#1
Thread Starter
New Member
[2005] Syntax error in INSERT INTO..in ado.net
hi,
im trying out a simple code in which i add data to my database.....
Code:
Dim dr As DataRow
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\rs232\rem.mdb;User Id=;Password=;"
Dim cmd As New OleDbCommand("INSERT INTO reminderdata (datetime, reminder)VALUES('" & txtdate.Text & "','" & txtreminder.Text & "')", New OleDbConnection(strconn))
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
but its giving me error saying Syntax error in INSERT INTO statement
so i tried the code given here
Code:
dr = ds.Tables(0).NewRow() 'Gets a reference to a new row.
dr("datetime") = txtdate.Text
dr("reminder") = txtreminder.Text
ds.Tables(0).Rows.Add(dr)
da.Update(ds)
ds.AcceptChanges()
and declared the insert command as
Code:
da.InsertCommand = New OleDbCommand("INSERT INTO reminderdata(datetime, reminder) VALUES(@datetime,@reminder)")
da.InsertCommand.Connection = conn
da.InsertCommand.Parameters.Add("@datetime", OleDbType.VarChar, 40, "datetime")
da.InsertCommand.Parameters.Add("@reminder", OleDbType.VarChar, 40, "reminder")
but i got the same error.....
plz help me resolve the error.....
Last edited by crystalsnehal; Apr 4th, 2008 at 07:01 AM.
-
Apr 4th, 2008, 03:26 AM
#2
Lively Member
Re: [2005] Syntax error in INSERT INTO..in ado.net
try putting [] round your fieldnames..
Code:
Dim cmd As New OleDbCommand("INSERT INTO reminderdata ([datetime], [reminder])VALUES('" & txtdate.Text & "','" & txtreminder.Text & "')", New OleDbConnection(strconn))
edit: it could be that datetime is a reserved word
-
Apr 4th, 2008, 03:55 AM
#3
Hyperactive Member
Re: [2005] Syntax error in INSERT INTO..in ado.net
 Originally Posted by crystalsnehal
hi,
Code:
Dim cmd As New OleDbCommand("INSERT INTO reminderdata (datetime, reminder)VALUES('" & txtdate.Text & "','" & txtreminder.Text & "')", New OleDbConnection(strconn))
is the datatype of datetime and reminder are DATETIME ???
if no then do them first ...
to insert datetime value don't give '" & txtdate.Text & "' double quote
just give " & txtdate.Text & "
double quote are used, when we insert varchar type data
thankx
koolprasad2003
MCP, MCTS, Microsoft MVP [Asp.Net/IIS]
For more .NET development tips visit .NET Tips
If the post is useful then please  Rate it
-
Apr 4th, 2008, 06:59 AM
#4
Thread Starter
New Member
Re: [2005] Syntax error in INSERT INTO..in ado.net
 Originally Posted by Jrogers
try putting [] round your fieldnames..
Code:
Dim cmd As New OleDbCommand("INSERT INTO reminderdata ([datetime], [reminder])VALUES('" & txtdate.Text & "','" & txtreminder.Text & "')", New OleDbConnection(strconn))
edit: it could be that datetime is a reserved word
Thanx for ur suggestion it worked.....
-
Apr 4th, 2008, 07:01 AM
#5
Thread Starter
New Member
Re: [2005] Syntax error in INSERT INTO..in ado.net
 Originally Posted by koolprasad2003
is the datatype of datetime and reminder are DATETIME ???
if no then do them first ...
to insert datetime value don't give '" & txtdate.Text & "' double quote
just give " & txtdate.Text & "
double quote are used, when we insert varchar type data
thankx
koolprasad2003 
no actually they both are of string type
-
Apr 4th, 2008, 07:17 AM
#6
Hyperactive Member
Re: [2005] Syntax error in INSERT INTO..in ado.net
fine.....
MCP, MCTS, Microsoft MVP [Asp.Net/IIS]
For more .NET development tips visit .NET Tips
If the post is useful then please  Rate it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|