Results 1 to 15 of 15

Thread: [RESOLVED] update field

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Resolved [RESOLVED] update field

    I tried to follow sample code to perform db update from this thread but none of them work in my case.

    That is 1 sample.
    1 Code:
    1. Using thiscon As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("direct_deliveryConnectionString").ConnectionString)
    2.             thiscon.Open()
    3.             Dim adapter As New SqlDataAdapter("SELECT pk_ddlvryMasterID,invno FROM tblDDlvryMaster WHERE pk_ddlvryMasterID=" & Me.rowID, thiscon)
    4.             Dim ds As New DataSet
    5.             adapter.Fill(ds, "tblDDlvryMaster")
    6.             With ds.Tables(0).Rows(0)
    7.                 .Item("invno") = invoiceTextBox.Text.ToString
    8.             End With
    9.             Dim cb As New SqlCommandBuilder(adapter)
    10.             adapter.Update(ds, "tblDDlvryMaster")
    11.         End Using

    2.
    2 Code:
    1. Using thiscon As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("direct_deliveryConnectionString").ConnectionString)
    2.             Using update As SqlCommand = New SqlCommand("update tblDDlvryMaster set invno=@invno where pk_ddlvryMasterID=@ID", thiscon)
    3.                 With update.Parameters
    4.                     .Add("@invno", SqlDbType.VarChar, 30, "invno").Value = invoiceTextBox.Text.ToString
    5.                     .Add("@id", SqlDbType.Int, 10, "pk_ddlvryMasterID").Value = Me.rowID
    6.                 End With
    7.  
    8.                 thiscon.Open()
    9.                 update.ExecuteNonQuery()
    10.  
    11.             End Using
    12.         End Using

    Both sample do not return error or anything and the web form just refresh when I hit update button.

    One thing strange more the code dont pause in breakpoints. I added around 3-4 breakpoints but none of them get hit.

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: update field

    Hello jlbantang,

    First things first...

    Have you executed the query that you are using directly against the database? i.e. have you made sure that your query is correct, and it is taking the appropriate action? I know your breakpoints are not getting hit yet, and the query isn't yet getting executed, but it is still the first thing that you should make sure you have right.

    Now, for the break points not getting hit...

    Which event is the above code in? The code itself looks fine, so as long as you put it in the right place, then it should do what you want it to.

    Gary

  3. #3
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: update field

    In the First Example the command builder should be ahead of the fill statement

    Code:
    Using thiscon As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("direct_deliveryConnectionString").ConnectionString)
                thiscon.Open()
                Dim adapter As New SqlDataAdapter("SELECT pk_ddlvryMasterID,invno FROM tblDDlvryMaster WHERE pk_ddlvryMasterID=" & Me.rowID, thiscon)
    Dim cb As New SqlCommandBuilder(adapter)
                Dim ds As New DataSet
                adapter.Fill(ds, "tblDDlvryMaster")
                With ds.Tables(0).Rows(0)
                    .Item("invno") = invoiceTextBox.Text.ToString
                End With
                
                adapter.Update(ds, "tblDDlvryMaster")
            End Using
    And also there is no need to open the connection thiscon.open. the fill method of dataset will automatically open the connection and close it.



    I strongly believe the second query will update the values
    Please mark you thread resolved using the Thread Tools as shown

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: update field

    Hi team,

    you guys always take early coffee

    @gep yes it is working in sql mgmt studio. code fires under button_click()

    @dana i was looking at the code like 10hrs but i cant find errors


    I prefer using 2nd code sample as its become my coding standard while working in winforms. Now, when i manually assign a value to the paramater field @invno the update works. While on the other hand when i use the invoicetextbox value the update dont do anything.

    This work.
    Code:
            Using thiscon As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("direct_deliveryConnectionString").ConnectionString)
                Using update As SqlCommand = New SqlCommand("update tblDDlvryMaster set invno=@invno where pk_ddlvryMasterID=@ID", thiscon)
                    With update.Parameters
    
                        .Add("@invno", SqlDbType.VarChar, 30, "invno").Value = "12345"
    
                        .Add("@id", SqlDbType.Int, 10, "pk_ddlvryMasterID").Value = Me.rowID
                    End With
    
                    thiscon.Open()
                    update.ExecuteNonQuery()
    
                End Using
            End Using
    Last edited by jlbantang; Jul 20th, 2010 at 02:19 AM.

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: update field

    jlbantang,

    I am confused! (maybe I need more coffee )

    From your first post, I took it to mean that your code wasn't getting executed. i.e. you set some breakpoints, and they weren't getting hit.

    From your last post though, it sounds like the code is being executed, but it just isn't doing what you want.

    Which is it?

    If you can set a breakpoint, set one on this line:

    Code:
    .Add("@invno", SqlDbType.VarChar, 30, "invno").Value = invoiceTextBox.Text.ToString
    What is the value of invoiceTextBox?

    Also, where is invoiceTextBox defined? Within the GridView row, or outside of the GridView?

    Gary

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: update field

    May be you trim the value before passing it to the Parameter collection.

    Code:
    .Add("@invno", SqlDbType.VarChar, 30, "invno").Value = invoiceTextBox.Text.Trim
    And more thing is that
    Code:
    invoiceTextBox.Text
    is a string and no .Tostring is required.
    Please mark you thread resolved using the Thread Tools as shown

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: update field

    OMG again ispostback is the culprit since under pageload I have code to filter the row details.
    So when i hit update_button the page reload again from its original value and get updated with the same value "MAKE SENSE AT ALL".


    BTW, why breakpoints does not hitting when i run the webform inside ms vstudio instead it works when it runs through web browser.

  8. #8
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: update field

    Doh!! Yip, that would definitely case a problem

    As for why debugging isn't working, are you pressing F5 to run the project, or CTRL + F5, or how are you starting the application?

    Gary

  9. #9
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: update field

    Quote Originally Posted by jlbantang View Post
    OMG again ispostback is the culprit since under pageload I have code to filter the row details.
    So when i hit update_button the page reload again from its original value and get updated with the same value "MAKE SENSE AT ALL".


    BTW, why breakpoints does not hitting when i run the webform inside ms vstudio instead it works when it runs through web browser.
    Then you put your update cod
    e,
    If Not Page.IsPostback method
    Please mark you thread resolved using the Thread Tools as shown

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: update field

    That case the issue!

    The webapp start from here
    I run it here to switch easily from source to the running page.

    So I'm moving forward with many things learn from u guys.

    Im thinking of showing a image while the process is handled. Do i need to create another webform to do that?

  11. #11
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: update field

    So, using that option will open the web page in a browser, without debugging.

    To start debugging, hit F5, or the green "play" button at the top.

    There would a number of way of doing that. Some people choose to you a loading gif, for instance:

    http://www.ajaxload.info/

    And then hide and show this once processing has completed.

    You could go as far as including AJAX in your project, and using an UpdatePanel with an animation. Or, like you say, include another form on the page.

    Gary

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: update field

    Quote Originally Posted by gep13 View Post
    So, using that option will open the web page in a browser, without debugging.

    To start debugging, hit F5, or the green "play" button at the top.

    There would a number of way of doing that. Some people choose to you a loading gif, for instance:

    http://www.ajaxload.info/

    And then hide and show this once processing has completed.

    You could go as far as including AJAX in your project, and using an UpdatePanel with an animation. Or, like you say, include another form on the page.

    Gary
    I check that suggestion one step at a time.

    Why I have to do webform apps...

  13. #13

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: [RESOLVED] update field

    I agree its rocking me to hell

  15. #15
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] update field

    Quote Originally Posted by jlbantang View Post
    I agree its rocking me to hell
    ha ha!!

    Stick with it, it will all start to make sense.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width