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

Why is this so complicated in ASP.NET?

Options
13»

Comments

  • Moderators, Science, Health & Environment Moderators Posts: 8,956 Mod ✭✭✭✭mewso


    Well I would expect that sql query to throw an error since you are naming 3 fields and passing it 5 values. Also to be on the safe side use the selecteditem.value as discussed above.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    This is the error I'm getting... Just wondering, when I used PHP, if I was passing values into a database and say there were 3 columns in the database and I was only passing in one value, I had to allow for an empty space in the INSERT command

    Something like: INSERT INTO My_Table("", "Car_Cost", "Seller_Name");

    Should I be doing something similar with this, because my table has around 7 columns and I'm only inserting 3 values?


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    If you are just passing in one value, then just specify the column in the first part of the insert.

    e.g. rather than:
    insert into my_table ('','','value1')

    You can do:

    insert into my_table(column)
    values('value1')


  • Registered Users Posts: 339 ✭✭duffman85


    I'm guessing you're using the cascading dropdown from the ajax control toolkit. There seems to be an issue with submitting the form according to the
    ajax controltoolkit website.

    Here's an extract from Using CascadingDropDown with a Database
    Finally, in order for the values to be submitted, EventValidation needs to be disabled for the page. EventValidation ensures that the values in each control match the values that were present when the page was rendered, but since these drop downs are populating on the client side, this is never true. We�re hoping to find a way to resolve this issue but please ensure that you understand the potential risks of this and validate the data appropriately in your post back when using this control.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    This was the cause of problem here...

    sql += "'" + radioValue + "'";
    sql += ")";

    I looked at the statement I was generating to insert the data into my database and whatever way I copied and pasted the code above in the c# script, it ended carrying a syntax error:

    The of the SQL statement ended up being...

    INSERT INTO...values("vehicle_make", "vehicle_Model", ");

    Instead of:


    INSERT INTO...values("vehicle_make", "vehicle_Model");


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


    duffman85 wrote: »
    I'm guessing you're using the cascading dropdown from the ajax control toolkit. There seems to be an issue with submitting the form according to the
    ajax controltoolkit website.

    Here's an extract from Using CascadingDropDown with a Database

    Yeah I've run into that as well, usually on page refresh. TBH if using ajax you should be calling webservice methods not asp.net page methods, its to do with the page life cycle and the events that get fired on an asynchronous postback.

    Also if you want to see if an event is firing set a breakpoint in the event code, instead of using Response.Write. Its quicker and easier and affords you much greater control over your debugging. VS comes with really powerful debugging tools and its well worth investing the time to learn them. Just put your cursor on the line of code you want to stop at and press F9.

    If your concatenating strings you shouldn't be using + to do it. Use one of the string concatenation methods like String.Format as they're much quicker and easier to work with. And I'd recommend you give you variables more meaningful names than dropdown1, dropdown2. Its a bad habit to get into.
    string sql = "insert into used_equipment (project_owner, project_status, creation_date) values ('{0}','{1}','{2}')";
    
    sql = String.Format(sql, dropdown1, dropdown2, dropdown3);
    

    By the by do you need the \n in your sql statement? Would it cause a problem? And yeah the MSDN library can be tricky to get around at first but you can use google instead of the MSDN search to do so, its much easier ironically :D


Advertisement