problem in Updating database in windows application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MuntaziM
    New Member
    • Feb 2009
    • 7

    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.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    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

    Comment

    • MuntaziM
      New Member
      • Feb 2009
      • 7

      #3
      //This the code for my form's save button as u can c....
      private void btnSave_Click(o bject sender, EventArgs e)
      {
      string fName = txtFirstName.Te xt;
      string lName = txtLastName.Tex t;
      string gender;
      if (rdbtnMale.Chec ked == true)
      {
      gender = "Male";
      }
      else
      {
      gender = "Female";
      }
      string email = txtEmail.Text;
      int age = Convert.ToInt16 (txtAge.Text);
      string address = txtAddress.Text ;
      int flag;
      flag = SHSProvider.Upd ateUserInfo(use rName, 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 = ConfigurationMa nager.Connectio nStrings["SHSDatabaseCon nectionString"].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.Execu teNonQuery(strc onn, "sp_UpdateUserI nfo", sqlparams);
      return flag;
      }

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

      ALTER PROCEDURE dbo.sp_UpdateUs erInfo
      @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.

      Comment

      • MuntaziM
        New Member
        • Feb 2009
        • 7

        #4
        Somebody help. I m stuck..

        Comment

        • ck9663
          Recognized Expert Specialist
          • Jun 2007
          • 2878

          #5
          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

          Comment

          • MuntaziM
            New Member
            • Feb 2009
            • 7

            #6
            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..o k?

            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.

            Comment

            • ck9663
              Recognized Expert Specialist
              • Jun 2007
              • 2878

              #7
              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

              Comment

              • MuntaziM
                New Member
                • Feb 2009
                • 7

                #8
                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..??

                Comment

                • ck9663
                  Recognized Expert Specialist
                  • Jun 2007
                  • 2878

                  #9
                  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

                  Comment

                  • MuntaziM
                    New Member
                    • Feb 2009
                    • 7

                    #10
                    i uninstalled sql Express and then installed completed sql server..
                    n thank God my problem is over..

                    Thanx CK.

                    Comment

                    Working...