473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

problem in Updating database in windows application

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
9 2248
ck9663
2,878 Expert 2GB
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
//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";
}
else
{
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");
}
else
{
MessageBox.Show("Sorry");
}
}

//........................
// 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)
AS
update [T_UserInfo] set [FirstName] = @fName, [LastName] = @lName, [Gender] = @gender, [email] = @email, [Age] = @age, [Address] = @address where [UserName] = @userName
RETURN
//.................................................. ...........................
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...
helpppPPP...!!
thanx.
Apr 8 '09 #3
Somebody help. I m stuck..
Apr 8 '09 #4
ck9663
2,878 Expert 2GB
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
how do i check the db while the application is runnung CK?
listen,
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 button.it 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
ck9663
2,878 Expert 2GB
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
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
ck9663
2,878 Expert 2GB
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
i uninstalled sql Express and then installed completed sql server..
n thank God my problem is over..

Thanx CK.
May 1 '09 #10

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

Similar topics

2
by: Ray | last post by:
I have a list of about 20,000 rows that I am updating. I loop through each row in my program and basically do the following (1) select * from TABLE where SID= for update /*lock the row*/ (2)...
0
by: vginders | last post by:
Hello, We have a legacy application which relies on an Access 97 database (upgrading is nog an option atm). As we are setting up a new server (Windows 2003), we started experiencing problems...
9
by: Víctor | last post by:
Hello, I'm filling a array of System.Diagnostic.Process by using GetProcesses() method. Due to a retard on this method, I do the call using a function and it passing like a delegate to one...
1
by: Doug Lim | last post by:
I have an ASP.NET application that I've developed using Visual Studio ..NET 2003 and I'm making use of Crystal Reports for .NET that's included to return reports back to the visitor's web browser...
7
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
6
by: Programatix | last post by:
Hi, I'm trying to distribute my application written using .NET Framework 2.0. It uses a MDB file for it's database. On certain machines with Windows XP (I have also tried updating them to...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
15
by: Scotty | last post by:
I like to have a good insert, update and delete code The code below sometimes workl ok sometimes doesnt work, what i am doing wrong?? Sub SaveAny() Dim command_builder As New...
6
by: x5Rb | last post by:
Database: 2 parent tables + 1 child table (child of both parent tables), enforcing foreign key constraints App: winformsapp, stuff (dataset, datatables, tableadatpers) generated by designer ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.