|
-
Nov 23rd, 2002, 06:17 PM
#1
Thread Starter
Lively Member
Database not updating!
Hi All,
Any boady know what is rong in this simble code, my DataRow and DataSet is update, but Database is not updating.
*** Note: I am using Sql - MSDE
myDR("bankname_a") = "US First Bank"
myDA.Update(myDS, "Bank")
myDS.AcceptChanges()
Thanks in advance
<><><><><><><><><><><><><><><><><><>
<><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
<><><><><><><><><><><><><><><><><><>
-
Nov 23rd, 2002, 07:49 PM
#2
Registered User
Do you get any errors or is it just not updating?
The code looks OK to me so if you dont get any error that means you forgot something elswhere in your code.
So....
if error, then what error?
if no error, more of your code will be needed to solve this I guess.
For example, is your UpdateCommand correctly written or did you use a commandbuilder to creat it?
/Leyan
-
Nov 24th, 2002, 04:05 PM
#3
Thread Starter
Lively Member
Athley, Thank you for your reply,
Yes I am using CommandBuilder, below is my related code in brief:
' Initiolize ....
Dim mySql = "SELECT * FROM AN_Bank"
Dim myDA As New SqlDataAdapter(mySql, myConn.oConnection)
Dim myCB As New SqlCommandBuilder(myDA)
Dim myDS As New DataSet()
Dim myDR As DataRow
Private Sub frm_Bank_Load
myDA.UpdateCommand = myCB.GetUpdateCommand
myDA.Fill(myDS, "Bank")
' Fill the DataRow
myDR = myDS.Tables("Bank").Rows(0)
Call DataBinding()
End Sub
Private Sub DataBinding()
Me.cbSelect.DataSource = myDS.Tables("bank").DefaultView
Me.cbSelect.DisplayMember = "BankName_e"
Me.txtBankName_e.DataBindings.Add("Text", myDS.Tables("Bank").DefaultView, "BankName_e")
Me.txtBankName_a.DataBindings.Add("Text", myDS.Tables("Bank").DefaultView, "BankName_a")
End Sub
Private Sub btnSave_Click
myDR("bankname_a") = "First Bank" ' This as test
myDA.Update(myDS, "Bank")
myDS.AcceptChanges()
End Sub
Thanks again
<><><><><><><><><><><><><><><><><><>
<><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
<><><><><><><><><><><><><><><><><><>
-
Nov 24th, 2002, 09:54 PM
#4
Addicted Member
Hi
You should have done databinding before you try to initializing a new command builder
-
Nov 25th, 2002, 01:19 AM
#5
Thread Starter
Lively Member
Hi,
You think it will work if I moved the Command Builder intiolization after the databinding?
<><><><><><><><><><><><><><><><><><>
<><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
<><><><><><><><><><><><><><><><><><>
-
Nov 25th, 2002, 02:10 AM
#6
Addicted Member
Yes
If you put after the bindings the command builder will then detect the tables that is being bind and automatically generate sql statement to update the database
-
Nov 25th, 2002, 03:03 AM
#7
Registered User
That shouln't make a difference as the commandbuilder builds the command from the adapter Select Query. At least that is what MS says, so it might have a difference. =)
/Leyan
Last edited by Athley; Nov 25th, 2002 at 03:09 AM.
-
Nov 25th, 2002, 03:03 AM
#8
Thread Starter
Lively Member
Thanks for the info.
I'll try out.
<><><><><><><><><><><><><><><><><><>
<><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
<><><><><><><><><><><><><><><><><><>
-
Nov 25th, 2002, 03:08 AM
#9
Registered User
One of my questions still stands, do you get an error or does it just dont update?
/Leyan
-
Nov 25th, 2002, 03:10 AM
#10
Thread Starter
Lively Member
Athley,
No, no errors, my dataset & data adapter are updated, when I move to next or previos record after the make the update i see the record is updated, but if I closed the form and re-connect and re-get my data from database I get the old data.
<><><><><><><><><><><><><><><><><><>
<><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
<><><><><><><><><><><><><><><><><><>
-
Nov 25th, 2002, 03:24 AM
#11
Addicted Member
Sorry my mistake
I think you should initialize your command builder after your dataset has been modifiy that is after the DS.AccepChanges , so that the command builder can generate the update command to update your database
-
Nov 25th, 2002, 03:43 AM
#12
Registered User
Ahhhh, I see. I think it has to do with the building of the dataset before you filled it. Change that order.
myDA.Fill(myDS, "Bank")
myDA.UpdateCommand = myCB.GetUpdateCommand
Else the adapter could not know what fields there are in the table for example
/Leyan
-
Nov 25th, 2002, 03:49 PM
#13
Thread Starter
Lively Member
I did what you said, but still the same problem.
Even I check the Sql database rights for update, everything is ok.!!!!!!!!!!
Any ieda what else could be the problem?
<><><><><><><><><><><><><><><><><><>
<><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
<><><><><><><><><><><><><><><><><><>
-
Nov 26th, 2002, 04:01 AM
#14
Registered User
Hmmm, I Created a SQL database with 2 fields ("BankName_a, "BankName_e"), added 2 textboxes and a combobox, copy/pasted your code added some to get a connection and changed some to get my events to fire and ...
Code:
Dim myConn As New SqlConnection("Integrated Security=SSPI;Data Source=LEYAN" _
& ";Initial Catalog=Snabel;")
Dim mySql = "SELECT * FROM AN_Bank"
Dim myDA As New SqlDataAdapter(mySql, myConn)
Dim myCB As New SqlCommandBuilder(myDA)
Dim myDS As New DataSet()
Dim myDR As DataRow
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
myDR("BankName_a") = "First Bank"
myDA.Update(myDS, "Bank")
myDS.AcceptChanges()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
myDA.Fill(myDS, "Bank")
myDA.UpdateCommand = myCB.GetUpdateCommand
myDR = myDS.Tables("Bank").Rows(0)
Me.cbselect.DataSource = myDS.Tables("bank").DefaultView
Me.cbselect.DisplayMember = "BankName_e"
Me.txtBankName_e.DataBindings.Add("Text", myDS.Tables("Bank").DefaultView, "BankName_e")
Me.txtBankName_a.DataBindings.Add("Text", myDS.Tables("Bank").DefaultView, "BankName_a")
End Sub
.... my database updates!!
Something but the code has to be wrong...
/Leyan
Last edited by Athley; Nov 26th, 2002 at 06:10 AM.
-
Nov 26th, 2002, 11:32 AM
#15
Thread Starter
Lively Member
YES, it's working....
The code looks ok, I don't know what was the problem, I've deleted some lines & re-code it again.
But, a new thing now....
Binding a field to a text property in a textbox does not mean accepting the modifications correct.....
When I remove this line (myDR("BankName_a") = "First Bank")
should I write the following to accept the changes from the textbox:
myDR("bankname_a") = Me.txtBankName_a.Text
myDR("bankname_e") = Me.txtBankName_e.Text
In addition to that in the previos example always the first row in the database table is updated! this means the dataadapter can't point to the correct record in the database!!!
Last edited by adsc; Nov 26th, 2002 at 11:39 AM.
<><><><><><><><><><><><><><><><><><>
<><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
<><><><><><><><><><><><><><><><><><>
-
Nov 27th, 2002, 03:01 AM
#16
Registered User
If you made changes and jumped to another record to make the changes to the dataset its just to make the update.
/Leyan
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
|