![]() |
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 |
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" /> </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.