|
-
Jul 20th, 2010, 01:03 AM
#1
Thread Starter
Fanatic Member
[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:
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 ds As New DataSet
adapter.Fill(ds, "tblDDlvryMaster")
With ds.Tables(0).Rows(0)
.Item("invno") = invoiceTextBox.Text.ToString
End With
Dim cb As New SqlCommandBuilder(adapter)
adapter.Update(ds, "tblDDlvryMaster")
End Using
2.
2 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 = invoiceTextBox.Text.ToString
.Add("@id", SqlDbType.Int, 10, "pk_ddlvryMasterID").Value = Me.rowID
End With
thiscon.Open()
update.ExecuteNonQuery()
End Using
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.
-
Jul 20th, 2010, 01:19 AM
#2
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
-
Jul 20th, 2010, 01:19 AM
#3
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
-
Jul 20th, 2010, 02:09 AM
#4
Thread Starter
Fanatic Member
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.
-
Jul 20th, 2010, 02:13 AM
#5
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
-
Jul 20th, 2010, 02:26 AM
#6
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
-
Jul 20th, 2010, 02:49 AM
#7
Thread Starter
Fanatic Member
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.
-
Jul 20th, 2010, 02:54 AM
#8
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
-
Jul 20th, 2010, 03:08 AM
#9
Re: update field
 Originally Posted by jlbantang
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
-
Jul 20th, 2010, 03:45 AM
#10
Thread Starter
Fanatic Member
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?
-
Jul 20th, 2010, 03:48 AM
#11
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
-
Jul 20th, 2010, 10:00 AM
#12
Thread Starter
Fanatic Member
Re: update field
 Originally Posted by gep13
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...
-
Jul 20th, 2010, 10:33 AM
#13
Re: [RESOLVED] update field
Because Web Forms Rock
-
Jul 20th, 2010, 10:36 AM
#14
Thread Starter
Fanatic Member
Re: [RESOLVED] update field
I agree its rocking me to hell
-
Jul 20th, 2010, 10:55 AM
#15
Re: [RESOLVED] update field
 Originally Posted by jlbantang
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|