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

Help with c# form ** Complete beginner :)

Options
  • 23-01-2007 5:40pm
    #1
    Closed Accounts Posts: 10


    I'm trying to write a form that takes the data and writes it to a table in a SQL database. Please bear in mind that I am a total beginner :)

    Heres the code I'm having problems with...

    protected void Submit_Click(object sender, EventArgs e)
    {

    string insStand_num_lbl = stand_num_lbl.Text;
    string insStand_num = stand_num.Text;
    string insStand_type_lbl = stand_type_lbl.Text;
    string insStand_type = stand_type.Text;
    string insComp_name = comp_name.Text;
    string insComp_name_lbl = comp_name_lbl.Text;
    string insComp_descript = comp_descript.Text;
    string insComp_descript_lbl = comp_descript_lbl.Text;
    string insLogo_upload_lbl = logo_upload_lbl.Text;
    string insLogo_upload = logo_upload.Text;

    SqlConnection insMp = new SqlConnection(ConfigurationManager.AppSettings["dbConnectionString"]);

    //string SQL = " INSERT INTO tbl_floor_plan";
    //SQL += "(stand_num, stand_type, comp_name, comp_descript, logo_upload) ";
    //SQL += "values ";
    //SQL += "('" + stand_num.Text + "',";
    //SQL += "'" + stand_type.Text + "',";
    //SQL += "'" + comp_name.Text + "',";
    //SQL += "'" + comp_descript.Text + "',";
    //SQL += "'" + logo_upload + "')";
    insMp.Open();

    string SQL = " INSERT INTO tbl_floor_plan";
    SQL += "values ";
    SQL += "('" + insStand_num + "',";
    SQL += "'" + insStand_type + "',";
    SQL += "'" + insComp_name + "',";
    SQL += "'" + insComp_descript + "',";
    SQL += "'" + insLogo_upload + "')";


    SqlCommand oSQL = new SqlCommand("", insMp);
    oSQL.CommandText = SQL;
    oSQL.ExecuteNonQuery();
    insMp.Close();
    insMp.Dispose();
    }

    As you can see from above I have tried a couple of different combinations and none seem to work properly..

    The error I'm getting is :
    for the line with: oSQL.ExecuteNonQuery();

    SQL exception was unhandled by user code.
    Line 1: Incorrect syntax near ')'.



    I'll love you forever if you are able to help. EEK!


Comments

  • Closed Accounts Posts: 10 eventz_user


    Oh god, it's working now.
    I was missing a space before values!!!
    dduuuh


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


    Heh :)

    It sucks when that happens.


Advertisement