Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

ASP.NET aspx language in dreamweaver

  • 19-03-2006 8:17am
    #1
    Closed Accounts Posts: 2


    :cool: I have tried inserting a simple first and last name into a access table via two textboxes using this code below:

    <%@ Page Language="VB"%>
    <%@ Import Namespace="System.Data"%>
    <%@ Import Namespace="System.Data.OleDb"%>


    <script runat="server">

    sub Button1_Click (Sender as Object, e as EventArgs)
    dim myConnection as new OleDbConnection ("Provider = " & "Microsoft.Jet.OLEDB.4.0;" & "Data Source = " & Server.MapPath("\aspnet\NeilStansfield\aspdatabase.mdb"))
    Dim cmd As New OleDbCommand("INSERT INTO regtest (firstname, password) VALUES('" & regtestname.Text & "','" & regtestpass.Text & "')")

    myConnection.Open()
    cmd.Connection = myConnection
    cmd.ExecuteNonQuery()
    myConnection.Close()



    end sub
    </SCRIPT>



    I keep getting the error returned for line 14(cmd.ExecuteNonQuery()) saying there is a syntax error in my insert statement but i cannot see how i think ihave miised a command or myCommand line

    if anyone can help it would be appreciated i am at university and my final year project needs to be in by Mayday ty.


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 9,035 Mod ✭✭✭✭mewso


    Change your code to use parameters to avoid sql injection.

    Dim cmd As New OleDbCommand("INSERT INTO regtest (firstname, password) VALUES(?,?)")
    cmd.Parameters.Add("FirstName", regtestname.Text)
    cmd.Parameters.Add("Password",
    regtestpass.Text)
    cmd.Connection = myConnection
    myConnection.Open()
    cmd.ExecuteNonQuery()
    myConnection.Close()

    I'm fairly sure you need to use ? for parameters in oledb but do a search for ms access parameter querys if you need more info.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    You may also want to put your connection string in the web.config file.


Advertisement