GridView does not show updated data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nonki
    New Member
    • Feb 2010
    • 5

    GridView does not show updated data

    Hi,

    When I click the update button on my Gridview to update oracle database, it does not show the updated values.. I need help urgently

    Code:
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
    
            OracleConnection oCon = new OracleConnection("Data Source=PSM1;User ID=MASTER;Password=MASTER");
            OracleCommand oCom = new OracleCommand("UPDATE SSU_EMPDETAILS SET SALARY_MODELING = 'salMod', APPL_GA20 = 'applGa20' WHERE UNIQUE_NO = 'unqNo'", oCon);
            oCom.Parameters.Add("unqNo", OracleDbType.Varchar2);
            oCom.Parameters.Add("salMod", OracleDbType.Varchar2);
            oCom.Parameters.Add("applGa20", OracleDbType.Varchar2);
    
            oCom.Parameters["unqNo"].Value = GridView1.DataKeys[e.RowIndex].Value.ToString();
            oCom.Parameters["salMod"].Value = GridView1.Rows[e.RowIndex].Cells[7].Controls[0];
            oCom.Parameters["applGa20"].Value = GridView1.Rows[e.RowIndex].Cells[8].Controls[0];
    
            oCon.Open();
            oCom.ExecuteNonQuery();
            oCon.Close();
            GridView1.EditIndex = -1;
            //GridView1.DataBind();
            BindData();
    
        }
    
        private void BindData()
        {
            OracleConnection oCon = new OracleConnection("Data Source=PSM1;User ID=CHRHRDM;Password=CHRHRDM");
            OracleDataAdapter oDa = new OracleDataAdapter("Select * from SSU_EMPDETAILS", oCon);
            //OracleDataAdapter oDa = new OracleDataAdapter("Select UNIQUE_NO,SALARY_MODELING,APPL_GA20 from SSU_EMPDETAILS", oCon);
            System.Data.DataSet oDs = new DataSet();
            oDa.Fill(oDs);
            GridView1.DataSource = oDs;
            GridView1.DataBind();
    }
    Last edited by tlhintoq; Feb 17 '10, 02:32 PM.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Database How-to parts 1 and 2
    Database tutorial Part 1
    Database tutorial Part 2

    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      I've never seen parameters used without the "@" symbol....

      I would have thought that your SQL query would have to look like this:
      Code:
      UPDATE SSU_EMPDETAILS SET SALARY_MODELING = @salMod, APPL_GA20 = @applGa20 WHERE UNIQUE_NO = @unqNo
      And that you would add your parameters like this:
      Code:
      oCom.Parameters.Add("@salMod", OracleDbType.Varchar2);
      oCom.Parameters.Add("@applGa20", OracleDbType.Varchar2);
      oCom.Parameters.Add("@unqNo", OracleDbType.Varchar2);
      And you would supply the values like this:
      Code:
      oCom.Parameters["@unqNo"].Value = GridView1.DataKeys[e.RowIndex].Value.ToString();
      oCom.Parameters["@salMod"].Value = GridView1.Rows[e.RowIndex].Cells[7].Controls[0];
      oCom.Parameters["@applGa20"].Value = GridView1.Rows[e.RowIndex].Cells[8].Controls[0];
      -Frinny

      Comment

      • Nonki
        New Member
        • Feb 2010
        • 5

        #4
        Originally posted by Frinavale
        I've never seen parameters used without the "@" symbol....

        I would have thought that your SQL query would have to look like this:
        Code:
        UPDATE SSU_EMPDETAILS SET SALARY_MODELING = @salMod, APPL_GA20 = @applGa20 WHERE UNIQUE_NO = @unqNo
        And that you would add your parameters like this:
        Code:
        oCom.Parameters.Add("@salMod", OracleDbType.Varchar2);
        oCom.Parameters.Add("@applGa20", OracleDbType.Varchar2);
        oCom.Parameters.Add("@unqNo", OracleDbType.Varchar2);
        And you would supply the values like this:
        Code:
        oCom.Parameters["@unqNo"].Value = GridView1.DataKeys[e.RowIndex].Value.ToString();
        oCom.Parameters["@salMod"].Value = GridView1.Rows[e.RowIndex].Cells[7].Controls[0];
        oCom.Parameters["@applGa20"].Value = GridView1.Rows[e.RowIndex].Cells[8].Controls[0];
        -Frinny
        Hi Frinny,

        At first my parameter had an "@" symbol but when I executed my code, I got an error saying "illegal Variable name" only then I realized that Oracle does not like "@" sign used with with parameter name.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          I have no experience working with Oracle through .NET
          I should have consulted MSDN before posting my last post...

          The MSDN Library is your best resource when developing any type of application in .NET. It contains many articles on every topic and it is where I usually go to for help first when I'm stuck on a problem. I recommend that you bookmark the MSDN Library link so that you can always have a reference to it when you are having problems.

          Here are 2 articles that I think you'll be interested in reading: the article on the OracleCommand.P arameters Property and also the article on the OracleParameter Class.

          Happy Coding!

          -Frinny

          Comment

          • Anotherone
            New Member
            • Feb 2010
            • 4

            #6
            Try FastSQLDataSour ce. It helps when you need faster display of large amounts of MS SQL Server data in your web application using grids, lists and other bound controls.
            It supports automatic paging and sorting and performs very quickly on large amounts of data
            It can work almost without coding or sometimes with no coding at all.

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Thanks for the info Anotherone... but Nonki is using Oracle.

              -Frinny

              Comment

              • Anotherone
                New Member
                • Feb 2010
                • 4

                #8
                Sorry, then just remove my post.

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  :) We don't delete useful information. Someone my come across this thread that isn't using oracle and may find your post useful. Its nice to learn about new controls once and a while even if it isn't all that helpful to the original question.

                  Comment

                  • semomaniz
                    Recognized Expert New Member
                    • Oct 2007
                    • 210

                    #10
                    Please use try catch block in your code. If there is an error this will reveal it. Also check the database itself if the data has been updated.

                    Also check you data type, your unique id is set to varchar is that right?

                    Comment

                    • Nonki
                      New Member
                      • Feb 2010
                      • 5

                      #11
                      Hi Guys,

                      I have changed my code as following and it updates nicely :)

                      Code:
                      OracleConnection oCon = new OracleConnection("Data Source=PSM1;User ID=MASTER;Password=MASTER");
                      
                      string unqNo = GridView1.DataKeys[e.RowIndex].Value.ToString();
                      string salMod = ((TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[0]).Text;
                      string applGa20 = ((TextBox)GridView1.Rows[e.RowIndex].Cells[8].Controls[0]).Text;
                      
                      string strSq = "UPDATE SSU_EMPDETAILS SET SALARY_MODELING = '" + salMod + "', APPL_GA20 = '" + applGa20 Where UNIQUE_NO = '" + unqNo + "' ;
                      
                      OracleCommand oCom = new OracleCommand(strSq, oCon);
                      
                      oCon.Open();
                      oCon.Close();
                      GridView1.EditIndex = -1;
                      BindData();

                      Does anyone know how to update a Date field in this way??

                      Thanks Everyone

                      Comment

                      • CroCrew
                        Recognized Expert Contributor
                        • Jan 2008
                        • 564

                        #12
                        Hello Nonki,

                        The code you just posted may do what you want it to do but, it is very vulnerable to SQL injection attacks.

                        I would find an alternative way of inserting into your database.

                        Happy Coding,
                        CroCrew~

                        Comment

                        Working...