Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Datagrid Control (http://www.velocityreviews.com/forums/f60-asp-net-datagrid-control.html)
-   -   how to connect asp.net with MS-access and also how to pass data to (http://www.velocityreviews.com/forums/t762984-how-to-connect-asp-net-with-ms-access-and-also-how-to-pass-data-to.html)

Jack 09-14-2006 01:06 AM

how to connect asp.net with MS-access and also how to pass data to
 
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


Ken Cox [Microsoft MVP] 09-18-2006 02:28 AM

Re: how to connect asp.net with MS-access and also how to pass data to
 
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>



"Jack" <Jack@discussions.microsoft.com> wrote in message
news:B32BBC01-D2C6-442B-BF46-99839543EF30@microsoft.com...
> 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
>





All times are GMT. The time now is 06:53 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57