Hi Guys ,
Have been reading the forum`s posts for a while.Found it really cool . So I joined.
I have a really silly problem.
I am trying to insert a record to a table in an access database on a click of a button .
I use web developer express and on the default page I have controls like dropdown lists, text boxes so on)
So what I want to achieve is :
Get the currently selected values in the controls(dropdowns, textboxes) on the page and insert them in the table Called DataStatus in Accesss database)
The Code I have behind the BtnTest Click (I called it Test as I wanted to test the thing first)
is:
Protected Sub BtnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnTest.Click
Dim insertRec As Boolean
Dim Conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DB\DataStatusRecord1.mdb")
Dim sql As String = "Insert into DataStatus(CedantID,CompanyType,CompanyName,TypeOfFile,FileName,ReportingPeriod,DateReceived)VALUES(@CedantID,@CompanyType,@CompName,@TypeOfFile,@FileName,@ReportingPeriod,@DateReceived) "
Dim sqlcmd As New System.Data.OleDb.OleDbCommand
Try
Conn.Open()
sqlcmd = New Data.OleDb.OleDbCommand(sql, Conn)
sqlcmd.Parameters.AddWithValue("@CedantID", DDCedantID.SelectedValue)
sqlcmd.Parameters.AddWithValue("@CompanyType", DDCompanyType.SelectedValue)
sqlcmd.Parameters.AddWithValue("@CompanyName", DDCompName.SelectedValue)
sqlcmd.Parameters.AddWithValue("@TypeOfFile", DDTypeOfFile.SelectedValue)
sqlcmd.Parameters.AddWithValue("@FileName", FileName.Text)
sqlcmd.Parameters.AddWithValue("@ReportingPeriod", Convert.ToDateTime(Calendar1.SelectedDate.ToString()))
sqlcmd.Parameters.AddWithValue("@DateReceived", ReciptDate.Text)
sqlcmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message.ToString)
insertRec = False
Finally
Conn.Close()
End Try
If insertRec Then
MsgBox("Details Submitted Successfully!")
Else : MsgBox("There was an error saving your data!")
End If
End Sub
I am getting the error I have specified :
"There was an error saving your data!"
I can`t really see what is wrong .
Nothing in the database as well.
Any help would be appreciated.
Thanks