[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.....:mad:
plz help me resolve the error.....
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
Re: [2005] Syntax error in INSERT INTO..in ado.net
Quote:
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:)
Re: [2005] Syntax error in INSERT INTO..in ado.net
Quote:
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.....:D
Re: [2005] Syntax error in INSERT INTO..in ado.net
Quote:
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
Re: [2005] Syntax error in INSERT INTO..in ado.net