locked
What is wrong with this query? RRS feed

  • Question

  • User1930286770 posted

    I have a page with three textboxes that get auto populated from a page load event. From there I have the ability to make some changes to the values and then click a button to write the data back to the Access Database. I have included the Button Click code below the WHERE CLASS = '" & userToDel & "' part works fine, the problem is the part of the query where my column names are. If I hard code values, the query executes fine. When I concatinate the textbox values in the query does not work. It does fail, it just doesn't work. What am I missing?

     

    Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateButton.Click

    Dim Conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("Class").ToString())

    Dim userToDel As String = Request.QueryString("rmvClass")Dim updateSQL As New OleDbCommand("UPDATE TRAINING SET INSTRUCTOR = '" & trainerTextBox.Text & "' , SUPER1 = '" & superuser1TextBox.Text & "' , SUPER2 = '" & superuser2TextBox.Text & "' where CLASS = '" & userToDel & "'", Conn)

    Conn.Open()

    updateSQL.ExecuteNonQuery()

    Conn.Close()

    Response.Redirect(
    "success.aspx")

    End Sub

    Thursday, August 14, 2008 10:13 AM

Answers

  • User1930286770 posted

    tompy_nation

    I didn't use the debugger but I did use a label to try to see what my page thought the vaule of the textbox was. Turns out the page was doing a postback and reloading the old data back into the textbox before executing the query. I added some code to handle this in my page load event and it is working fine now. Thanks for your guidance.

     Jim

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 14, 2008 11:12 AM

All replies

  • User-298277035 posted

    For me query looks good. Can you try  with parameters insted textboxes directly in to query..

    Thursday, August 14, 2008 10:28 AM
  • User1930286770 posted

    Yes I did that and it works fine. Thats what I don't understand...

    Thursday, August 14, 2008 10:31 AM
  • User-1203469223 posted

    change you're where clausule to a fix value and see if that works...

    I guess there is just something wrong with that field?

    What kind of field is that in your where clausule?

    Thursday, August 14, 2008 10:50 AM
  • User1930286770 posted

    My where is a text field. If I hard code my set clauses and leave my where clause alone the query works fine. I will try it though.

    Thursday, August 14, 2008 10:56 AM
  • User1930286770 posted

    I tried hard coding where and that did not work.

    Thursday, August 14, 2008 10:58 AM
  • User-1203469223 posted

     

    have you used the debugger to see that you get .Text value of the textbox inside the sql statement when updating?
    Thursday, August 14, 2008 11:00 AM
  • User-1199946673 posted

    Yes I did that and it works fine. Thats what I don't understand...

    So you tried it the right way, and you want to know why the wrong way doesn't not work?

    When you do it the wrong way, it depends what you enter in te textboxes...

    Thursday, August 14, 2008 11:02 AM
  • User1930286770 posted

    tompy_nation

    I didn't use the debugger but I did use a label to try to see what my page thought the vaule of the textbox was. Turns out the page was doing a postback and reloading the old data back into the textbox before executing the query. I added some code to handle this in my page load event and it is working fine now. Thanks for your guidance.

     Jim

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 14, 2008 11:12 AM