How to insert Form records in MS Access database using asp.net

First of all give full access permission to all database .mdb files by right click> properties> permissions

Make a function

Function insertRecord(ByVal mysql As String) As Boolean
Dim DBconn = New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "DATA SOURCE=" & Server.MapPath("") & "\database\circulars.mdb;")
Dim DBcmd As New OleDb.OleDbCommand(mysql, DBconn)
Try

DBcmd.Connection.Open()
DBcmd.ExecuteNonQuery()
DBcmd.Connection.Close()
insertRecord = True


Catch exc As Exception

DBcmd.Connection.Close()
Span1.InnerHtml = "Error: Unable To Submit Circular : Please Contact IT Dept
" & exc.Message()

insertRecord = False
End Try

End Function

You can call this function by getting data from Form like this at submit button click event.

Dim mysql As String = "Insert Into circulars ( cno, cdate,cdatetxt,vdate,sub,scope, name,dept, filename)" & _
"VALUES (" & _
"'" & Replace(txtCno.Text, "'", "''") & "', " & _
"'" & ddlDate.SelectedItem.Text & "-" & ddlMonth.SelectedItem.Text & "-" & ddlYear.SelectedItem.Text & "', " & _
"'" & ddlDate.SelectedItem.Text & "-" & ddlMonth.SelectedItem.Text & "-" & ddlYear.SelectedItem.Text & "', " & _
"'" & ddlVdate.SelectedItem.Value & "-" & ddlVmonth.SelectedItem.Value & "-" & ddlVyear.SelectedItem.Text & "', " & _
"'" & Replace(txtSub.Text, "'", "''") & "', " & _
"'" & Replace(Scope, "'", "''") & "', " & _
"'" & Replace(Session("ename"), "'", "''") & "', " & _
"'" & Replace(Session("dept"), "'", "''") & "', " & _
"'" & Replace(TheFile, "'", "''") & "') "
If insertRecord(mysql) = False Then
Span1.InnerHtml = "Unable to insert in to users " & mysql
Return
Else
txtCno.Text = ""
txtSub.Text = ""
End If

It will look like this

Comments

praveen said…
PRAVEEN::I tried many times but i didn't get any ip address as you said............Is there any other way to get it.....?????
If so please help me out to get it.

E-mail::pavi.praveen7@gmail.com
Vinod Kotiya said…
why do u need ip address in msaccess