Hi all,
I have taken the plunge to move away from regular html forms with and all client side coding in to asp.net. Server side scripting is totally alien to me but atleast you can write in VB (I am used to VBA but it is close enough to be able to get by).
I have a form which currently submits information to an access database using javascript however I am looking to move this to asp.net. I have looked at numerous tutorials and found a half decent example which I got working in visual web developer.
The code is as follows:
My question is whether this is the typical way to do this? I have seen a couple of examples of regular asp files being used within a form post to which then execute the new record insert. But I have since read in aspx you do not need this separate file at all.
Just looking for some reassurance and advice here.
Thanks,
Chris
I have taken the plunge to move away from regular html forms with and all client side coding in to asp.net. Server side scripting is totally alien to me but atleast you can write in VB (I am used to VBA but it is close enough to be able to get by).
I have a form which currently submits information to an access database using javascript however I am looking to move this to asp.net. I have looked at numerous tutorials and found a half decent example which I got working in visual web developer.
The code is as follows:
Code:
<%@ Import Namespace="System.Data.OleDb" %> <script runat="server"> Sub submit(sender As Object, e As EventArgs) Dim conCoaxis As OleDbConnection Dim strInsert As String Dim cmdInsert As OleDbCommand Dim dtmDate As DateTime dtmDate = DateTime.Now() conCoaxis=New OleDbConnection(“Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath(“email.mdb")) strInsert = “INSERT INTO email (Email, Fname, CompanyName, [Date]) Values (@Email, @Fname, @CompanyName, @Date)" cmdInsert = New OleDbCommand( strInsert, conCoaxis ) cmdInsert.Parameters.Add( “@Email", txtEmail.Text ) cmdInsert.Parameters.Add( “@Fname", txtName.Text ) cmdInsert.Parameters.Add( “@CompanyName", txtCompany.Text ) cmdInsert.Parameters.Add( “@Date", OleDbType.Date).Value = dtmDate.ToString(“g") Try conCoaxis.Open() cmdInsert.ExecuteNonQuery() conCoaxis.Close() Response.Write(“Updated Successfully!<p> </p><p> </p><p> </p>") Catch conCoaxis.Close() End Try End Sub </script> <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN" “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“> <html xmlns="http://www.w3.org/1999/xhtml“> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <form runat="server" id="form1" name="form1" method="post" action=""> Name: <asp:TextBox id="txtName" runat=server /> Email: <asp:TextBox id="txtEmail" runat=server /> Company: <asp:TextBox id="txtCompany" runat=server /> <asp:Button id="id" text="Submit" OnClick="submit" runat=server /> </form> </body> </html>
Just looking for some reassurance and advice here.
Thanks,
Chris
Comment