hi, when i update records in VB, only 0's are stored in database, can anyone halp me to solve this? send me appropriate code for this?


Can you Post your code (Saving Part) here..? so that somebody can point out the problem...


hi ,
I am using VB and SQL Server as backend. and my coding is .... follows..
[ dim con as connection ]
[dim rst as recordset ]
In page load,
[ set con = new connection ]
[ set rst = new recordset ]
[ con.open " provider=SQLOLEDB;initialcatalog=preethi;database=ACER;integrated security=sspi]
' preethi -> database name, ACER -> server name
[ rst.open"select * from tablename",adOpenkeyset,adLockOptimistic ]
[ rst.activeconnection = con ]
[ loadcontrols ]

Im using a button for adding new records and i have named the button as Addnew.
in that button click event the coding is...
[ clearcontrols ]
[rst.addnew ]
[ loadrecords ]
[rst.update ]

loadrecords is a private fuction,
[rst!fieldname1=val(text1.text) ]
[ rst!fieldname2=val(text2.text) ]

clearcontrols is also private function,
[text1.text = " " ]
[text2.text = " " ]

private sub loadcontrols()
[ text1.text = rst!fieldname1 ]
[ text2.text = rst!fieldname2 ]

And also i have Update button, in that update-click event i have the following coding,
[ rst.update ]

So if i update records, only 0's are stored in database. so can u help me to solve this?

Actually in AddNew button, you just give

[ clearcontrols ]
[rst.addnew ]
[ loadrecords ]
[rst.update ]

replace it as


and if the user press UpdateButton then u save the record, that is


instead of

[ rst.update ]

You are given that when user press AddNew it will create a new record without getting the input and it updates to the table. Then if click Update button, 0 will be updated. because u are not using loadrecords function in Update Button


I guess, your Field1 and 2 in table are of string/text type, and you are saving Val(text1.text)....?
Val() functions converts the text value to string..
So change the Load records like this :


also check Selva's points above..


I think your tips will be help full to me. thanks for your responces. I will try it out and then i will get you back if again any problem occurs.

This article has been dead for over six months. Start a new discussion instead.