tri_inn Level: Regular User Registered: 26-08-2002 Posts: 395
|
Encounter error at the time of inserting data to table?
i have simple webform which will insert data to ms-access2000 database but when i am going to insert data
in my table that i am getting one error repeatedly
that is 'Syntax error in INSERT INTO statement.'
just i can't understand what is wrong in my coding but when i am changing my database from
access2000 to Sqlserver2000 then it works fine.so it is getting confusing for me.
please tell me how could i fix the error.why i am getting error when my database is access2000 but
the same code works fine just when my database is sqlserver.is it a bug of asp.net.
please please tell me how could fixed the error when my database is access2000 because i am in
great problem.
i am simply giving you the only portion which will insert new record to access2000 database
my code follows
----------------
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("ScheduleDB.mdb"))
'Dim cn As New OleDbConnection("Provider=SQLOLEDB.1;Password=sa;User ID=sa;Initial Catalog=pubs")
Dim daAdd As New OleDbDataAdapter("select * from Myevent", cn)
Dim drAdd As DataRow
Dim dsAdd As New DataSet()
Dim cmdAdd As OleDbCommandBuilder
Try
Dim tm() As String = Split(ddlTime.SelectedItem.Text, "-")
cmdAdd = New OleDbCommandBuilder(daAdd)
daAdd.Fill(dsAdd, "event")
drAdd = dsAdd.Tables("event").NewRow
drAdd("day") = ddlDay.SelectedItem.Text
drAdd("month") = ddlMonth.SelectedItem.Text
drAdd("year") = ddlYear.SelectedItem.Text
drAdd("starttime") = tm(0)
drAdd("endtime") = tm(1)
drAdd("event_info") = txtEvent.Text
dsAdd.Tables("event").Rows.Add(drAdd)
daAdd.Update(dsAdd, "event")
lblmsg.Visible = True
lblmsg.Text = "1 Record inserted..."
cn.Close()
Catch ex As OleDbException
lblmsg.Visible = True
lblmsg.Text = ex.StackTrace.ToString
End Try
End Sub
|