how to connect asp.net with MS-access and also how to pass data to

J

Jack

hI,

Anyone here know how to connect asp.net with MS-access and also how to pass
data to a table?

The following is the code which I have but unfortunately its not working..
Public Connectionstring As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source =
C:\Inetpub\wwwroot\Dee\ASPdotnet\currt.mdb;Persist Security Info=False;"
Public con As New OleDbConnection(Connectionstring)


Dim strSelect As String
strSelect = "Insert Into UserDetails1 (Username) Values
(@DetailsUser)"
Dim cmd As New OleDbCommand(strSelect, con)
Dim added As Integer
cmd.Parameters.Add("@DetailsUser", txtUserDetails.Text)

Try
con.Open()
cmd.ExecuteNonQuery()
Response.Write("Updated Successfully!<p> </p><p> </p><p> </p>")

con.Close()
Response.Write("Updated Successfully!<p> </p><p> </p><p> </p>")
Catch
con.Close()
End Try



Thanks in advance
Jack
 
K

Ken Cox [Microsoft MVP]

Hi Jack,

Here's some code that seems to do what you want.

Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Button1_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Connectionstring As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & _
"C:\ASPNETWeb\App_Data\currt.mdb;Persist Security Info=False;"
Dim con As New Data.OleDb.OleDbConnection _
(Connectionstring)

Dim strSelect As String
strSelect = "Insert Into UserDetails1 (Username) Values " & _
"(@DetailsUser)"
Dim cmd As New Data.OleDb.OleDbCommand(strSelect, con)
Dim pms As Data.OleDb.OleDbParameterCollection
pms = cmd.Parameters
pms.Add("@DetailsUser", Data.OleDb.OleDbType.VarChar, 50)
pms("@DetailsUser").Value = Server.HtmlEncode(txtUserDetails.Text)
Try
con.Open()
cmd.ExecuteNonQuery()
Response.Write _
("Updated Successfully!<p> </p><p> </p><p> </p>")
Catch exc As Exception
Response.Write("Problem: " & exc.Message & _
"<p> </p><p> </p><p> </p>")
Finally
con.Close()
End Try
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Insert into Access Database</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:textbox id="txtUserDetails" runat="server"></asp:textbox><br />
<br />
<asp:button id="Button1" runat="server" onclick="Button1_Click"
text="Insert" />&nbsp;</div>

</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top