By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,659 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,659 IT Pros & Developers. It's quick & easy.

problem in Updating database in windows application

P: 7
Hi all.

i am designing a windows application in visual studio 2005.
i display user information from user table in text boxes on a form through stored procedures.It works fine.
Then i edit some of the fields and save these changes by clicking on save button. which in turn calls a stored procedure to reflect the changes in the database i.e user table.
then i retrieve this info. i get the updated information. fine.

then i close the application by this.close() method.
when i login again i get the old information.
it looks like the database was temporarily updated.
do i need to set any properties or something..
remember its a windows application not a web appl.

please help.
Apr 7 '09 #1
Share this Question
Share on Google+
9 Replies

Expert 2.5K+
P: 2,878
How do you save the information? Do you issue a T-SQL update statement? Post your UPDATE statement and let's see what we can do.

--- CK
Apr 8 '09 #2

P: 7
//This the code for my form's save button as u can c....
private void btnSave_Click(object sender, EventArgs e)
string fName = txtFirstName.Text;
string lName = txtLastName.Text;
string gender;
if (rdbtnMale.Checked == true)
gender = "Male";
gender = "Female";
string email = txtEmail.Text;
int age = Convert.ToInt16(txtAge.Text);
string address = txtAddress.Text;
int flag;
flag = SHSProvider.UpdateUserInfo(userName, fName, lName, gender, email, age, address);
if (flag == 1)
MessageBox.Show("Your Account Has been changed successfully");

// this is the update function in my provider...

public static int UpdateUserInfo(string userName, string fName, string lName, string gender, string email, int age, string address)
string strconn = ConfigurationManager.ConnectionStrings["SHSDatabaseConnectionString"].ToString();
SqlParameter[] sqlparams = new SqlParameter[7];
sqlparams[0] = new SqlParameter("@userName", userName);
sqlparams[1] = new SqlParameter("@firstName", fName);
sqlparams[2] = new SqlParameter("@lastName", lName);
sqlparams[3] = new SqlParameter("@gender", gender);
sqlparams[4] = new SqlParameter("@email", email);
sqlparams[5] = new SqlParameter("@age", age);
sqlparams[6] = new SqlParameter("@address", address);
int flag = SqlHelper.ExecuteNonQuery(strconn, "sp_UpdateUserInfo", sqlparams);
return flag;

// and finally this is my Stored procedure...

ALTER PROCEDURE dbo.sp_UpdateUserInfo
@userName nvarchar(30),
@fName nvarchar(30),
@lName nvarchar(30),
@gender nvarchar(10),
@email nvarchar(30),
@age int,
@address nvarchar(30)
update [T_UserInfo] set [FirstName] = @fName, [LastName] = @lName, [Gender] = @gender, [email] = @email, [Age] = @age, [Address] = @address where [UserName] = @userName
//.................................................. ...........................
when i execute this stored procedure it works fine..
plus i have used the same provider in my web application, it works fine there also, so i dont think any changes need to be made in SP or Provider function...
Apr 8 '09 #3

P: 7
Somebody help. I m stuck..
Apr 8 '09 #4

Expert 2.5K+
P: 2,878
Isolate your problem.

After clicking Save, do not close your application, check the db if the changes got affected. If it does and the application still shows the old value, that would mean it's your recordset. The value of your recordset is still in the memory that's why it's displaying the old value. Try refreshing your recordset.

If the changes were not affected, it's your UPDATE t-sql.

--- CK
Apr 8 '09 #5

P: 7
how do i check the db while the application is runnung CK?
I m using win application.. and i have kept a back link on it that takes me 2 the previous form. see what happens

I have two buttons showUserInfo and SaveUserInfo..ok?

Clicking on showUserInfo retrieves data from db and displays it on the form.

then say i edit age or address of user and click on saveUserInfo returns me success.

I now again click on ShowUserInfo and it retrieves me the Info that i just updated.even if i go to the previos form and and then again to this form, i can c the updated info. As long as i m in the same run of the application i can c the updated info.

Now when i quit the appliaction by .close() method. and run the application again, It shows me the old info, that means the db was not updated.

when i open the userInfo Table, it is not updated.

my save and show buttons call Data Access Layer functions which in turn call Stored procedures.
Apr 9 '09 #6

Expert 2.5K+
P: 2,878
That means you have to open a sql server management studio to view the tables after you click the Save.There are a lot of possible reason why it's not updating. It could be the user credential that you used does not have proper rights, it could be the connection that you use does not commit automatically, it could be the update is happening on the recordset front-end level and not on the back-end. Since you can successfuly run this stored proc independently, it points out to your front-end tool as the issue, not SQL Server.

--- CK
Apr 9 '09 #7

P: 7
Yes Ck may b thats right.. now tell me i don have the complete sql server mngmnt studio.. i m using sql express. can it be bcoz of sql express.

but remember as i mentioned i have the same web application as my win application. but web app is not givin me any problemz.
the problem iz only with win application.
What do u think..??
Apr 10 '09 #8

Expert 2.5K+
P: 2,878
It could be anything. SQL Express also have limitations on number of connections. But my suspect is your connection and recordset properties. All updates are happening on your front-end and not on the back-end. That's why your app is displaying updated info but not reflected in your DB.

Happy Coding!

--- CK
Apr 10 '09 #9

P: 7
i uninstalled sql Express and then installed completed sql server..
n thank God my problem is over..

Thanx CK.
May 1 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.