none
Need help with Asp.net file RRS feed

  • Question

  • Hello,

    I am trying to create a website that takes input from user and then executes a asp.ney file that will transfer data into a table that is in MS Access. Below is the code from the asp.net file. But when I click on Submit on the webpage, a pop up comes up that asks me to either open or save the asp file. And no matter what I select it doesnt actually transfer the data into the Access table.

    <% @ Language="VBScript" %>
    <% Option Explicit %>
    <html>
    <head>
    <title>Form to database</title>
    </head>
    <body>
    <%
    'declare your variables
    Dim Card#, FirstName, LastName, DOB, CellPhone, Gender, StoreName, EmailAddress
    Dim sConnString, connection, sSQL

    ' Receiving values from Form, assign the values entered to variables
    Card# = Request.welcome.html("Card#")
    FirstName = Request.welcome.html("FirstName")
    LastName =Request.welcome.html("LastName")
    DOB =Request.welcome.html("DOB")
    CellPhone =Request.welcome.html("CellPhone")
    Gender =Request.welcome.html("Gender")
    StoreName =Request.welcome.html("StoreName")
    EmailAddress =Request.welcome.html("EmailAddress")

    'declare SQL statement that will query the database
    sSQL = "INSERT into G&L Table (Card#, First Name, Last Name, DOB, Cell Phone, Gender, Store Name, Email Address) values ('" & Card# & "', '" & FirstName & "', '" & LastName & "', '" & DOB & "', '" & CellPhone & "', '" & Gender & "', '" & StoreName & "','" & EmailAddress & "',)"

    'define the connection string, specify database
    'driver and the location of database
    sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & Server.MapPath("Test1.accdb")


    'create an ADO connection object
    Set connection = Server.CreateObject("ADODB.Connection")

    'Open the connection to the database
    connection.Open(sConnString)

    'execute the SQL
    connection.execute(sSQL)

    response.write "The form information was inserted successfully."

    ' Done. Close the connection object
    connection.Close
    Set connection = Nothing
    %>
    </body>
    </html>

    Thursday, September 30, 2010 12:02 AM

Answers

  • Hello,

    I am trying to create a website that takes input from user and then executes a asp.ney file that will transfer data into a table that is in MS Access. Below is the code from the asp.net file. But when I click on Submit on the webpage, a pop up comes up that asks me to either open or save the asp file. And no matter what I select it doesnt actually transfer the data into the Access table.

    <% @ Language="VBScript" %>
    <% Option Explicit %>
    <html>
    <head>
    <title>Form to database</title>
    </head>
    <body>
    <%
    'declare your variables
    Dim Card#, FirstName, LastName, DOB, CellPhone, Gender, StoreName, EmailAddress
    Dim sConnString, connection, sSQL

    ' Receiving values from Form, assign the values entered to variables
    Card# = Request.welcome.html("Card#")
    FirstName = Request.welcome.html("FirstName")
    LastName =Request.welcome.html("LastName")
    DOB =Request.welcome.html("DOB")
    CellPhone =Request.welcome.html("CellPhone")
    Gender =Request.welcome.html("Gender")
    StoreName =Request.welcome.html("StoreName")
    EmailAddress =Request.welcome.html("EmailAddress")

    'declare SQL statement that will query the database
    sSQL = "INSERT into G&L Table (Card#, First Name, Last Name, DOB, Cell Phone, Gender, Store Name, Email Address) values ('" & Card# & "', '" & FirstName & "', '" & LastName & "', '" & DOB & "', '" & CellPhone & "', '" & Gender & "', '" & StoreName & "','" & EmailAddress & "',)"

    'define the connection string, specify database
    'driver and the location of database
    sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & Server.MapPath("Test1.accdb")


    'create an ADO connection object
    Set connection = Server.CreateObject("ADODB.Connection")

    'Open the connection to the database
    connection.Open(sConnString)

    'execute the SQL
    connection.execute(sSQL)

    response.write "The form information was inserted successfully."

    ' Done. Close the connection object
    connection.Close
    Set connection = Nothing
    %>
    </body>
    </html>


    what about if under your execute SQL, you put connection.EXECUTENONQUERY ?

    as for the sequence, is better to declare the connection string 1st...move the connection string up to top.

    i have a set of code which will insert data to access, let me know if you want it...but the way of writting is different....

    Saturday, October 2, 2010 4:12 AM
    Answerer

All replies

  • Hello,

    I am trying to create a website that takes input from user and then executes a asp.ney file that will transfer data into a table that is in MS Access. Below is the code from the asp.net file. But when I click on Submit on the webpage, a pop up comes up that asks me to either open or save the asp file. And no matter what I select it doesnt actually transfer the data into the Access table.

    <% @ Language="VBScript" %>
    <% Option Explicit %>
    <html>
    <head>
    <title>Form to database</title>
    </head>
    <body>
    <%
    'declare your variables
    Dim Card#, FirstName, LastName, DOB, CellPhone, Gender, StoreName, EmailAddress
    Dim sConnString, connection, sSQL

    ' Receiving values from Form, assign the values entered to variables
    Card# = Request.welcome.html("Card#")
    FirstName = Request.welcome.html("FirstName")
    LastName =Request.welcome.html("LastName")
    DOB =Request.welcome.html("DOB")
    CellPhone =Request.welcome.html("CellPhone")
    Gender =Request.welcome.html("Gender")
    StoreName =Request.welcome.html("StoreName")
    EmailAddress =Request.welcome.html("EmailAddress")

    'declare SQL statement that will query the database
    sSQL = "INSERT into G&L Table (Card#, First Name, Last Name, DOB, Cell Phone, Gender, Store Name, Email Address) values ('" & Card# & "', '" & FirstName & "', '" & LastName & "', '" & DOB & "', '" & CellPhone & "', '" & Gender & "', '" & StoreName & "','" & EmailAddress & "',)"

    'define the connection string, specify database
    'driver and the location of database
    sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & Server.MapPath("Test1.accdb")


    'create an ADO connection object
    Set connection = Server.CreateObject("ADODB.Connection")

    'Open the connection to the database
    connection.Open(sConnString)

    'execute the SQL
    connection.execute(sSQL)

    response.write "The form information was inserted successfully."

    ' Done. Close the connection object
    connection.Close
    Set connection = Nothing
    %>
    </body>
    </html>


    what about if under your execute SQL, you put connection.EXECUTENONQUERY ?

    as for the sequence, is better to declare the connection string 1st...move the connection string up to top.

    i have a set of code which will insert data to access, let me know if you want it...but the way of writting is different....

    Saturday, October 2, 2010 4:12 AM
    Answerer
  • scngan,

    I'd like to see your code sample.  I'm trying to do the same thing. unfortunately, trying the code from zehra2 isn't working for me.

    Tuesday, November 9, 2010 6:12 AM
  • scngan,

    I'd like to see your code sample.  I'm trying to do the same thing. unfortunately, trying the code from zehra2 isn't working for me.


    hi, you can get from my blog. http://blog.scnetstudio.com/post/2009/03/24/How-to-add-data-to-database-using-VBNET.aspx
    Tuesday, November 9, 2010 9:23 AM
    Answerer