Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

insert statement into mysql with asp.net

  • 18-11-2006 03:15PM
    #1
    Registered Users, Registered Users 2 Posts: 872 ✭✭✭


    im having trouble inserting form values into a mySQL database

    Im can insert the following static statement no problem

    string sql = "INSERT INTO mailinglist (name,email) VALUES('my name','my email')";

    MySqlCommand cmd = new MySqlCommand(sql, conn)

    but i need to do this with form values and i thought i'd just be able to add variable values to the end of the SQL string but it's throwing errors.

    string sql = "INSERT INTO mailinglist (name,email) VALUES("+name.Text+","+email.Text+")";

    Any ideas ? ( it's probably simple). Can i use parameters ?

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    What are the errors that you're getting?

    Though I can spot one thing straight off - you're not using any quotes when inserting text values, e.g.

    string sql = "INSERT INTO mailinglist (name,email) VALUES('"+name.Text+"','"+email.Text+"')";


  • Registered Users, Registered Users 2 Posts: 872 ✭✭✭grahamor


    that seems to have solved it Seamus, thanks for the help.


Advertisement