Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Please help with inserting GridView Values in oracle table

Please help with inserting GridView Values in oracle table

Scheduled Pinned Locked Moved ASP.NET
csharpcssdatabaseoraclesysadmin
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hammad Mansoor
    wrote on last edited by
    #1

    Hi all I have a grid view which is used to delete the data in it. I want the data to be stored in another table before it is deleted from the actual table. The database is in Oracle. I am using the following code. Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) Handles GridView1.RowDeleting Dim oradb As String = "Data Source=(DESCRIPTION=" _ + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=Mahasilbkp.ltuisb.net)(PORT=1521)))" _ + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=db21a)));" _ + "User Id=;Password=;pooling=false;enlist=false;" Dim conn1 As New OracleConnection(oradb) conn1.Open() Dim cmd1 As New OracleCommand cmd1.Connection = conn1 GridView1.DataBind() cmd1.CommandText = "insert into uu.record_backup(ntn, name, status, enf, aud, sector, delete_user) select ntn, name, status, enf, aud, sector" + ",'" + Label5.Text + "'" + " " + "from uu.total_cases where trim(ntn)=" + "'" + GridView1.SelectedValue + "'" Dim dr1 As OracleDataReader = cmd1.ExecuteReader() dr1.Read() dr1.Dispose() dr1.Close() cmd1.Dispose() conn1.Dispose() conn1.Close() End Sub The insert command execute perfectly if I remove the GridView1.SelectedValue. But it does not give the desired result as I want the value displayed in the data grid to be inserted only, before it is deleted. What happens in the above code is that data is deleted from the actual table, but nothing is inserted in the backup table described in the code above. I understand I need to write something else instead of GridView1.SelectedValue, but I can't think of anything else. Please help me with this. Thanks.

    J H 2 Replies Last reply
    0
    • H Hammad Mansoor

      Hi all I have a grid view which is used to delete the data in it. I want the data to be stored in another table before it is deleted from the actual table. The database is in Oracle. I am using the following code. Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) Handles GridView1.RowDeleting Dim oradb As String = "Data Source=(DESCRIPTION=" _ + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=Mahasilbkp.ltuisb.net)(PORT=1521)))" _ + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=db21a)));" _ + "User Id=;Password=;pooling=false;enlist=false;" Dim conn1 As New OracleConnection(oradb) conn1.Open() Dim cmd1 As New OracleCommand cmd1.Connection = conn1 GridView1.DataBind() cmd1.CommandText = "insert into uu.record_backup(ntn, name, status, enf, aud, sector, delete_user) select ntn, name, status, enf, aud, sector" + ",'" + Label5.Text + "'" + " " + "from uu.total_cases where trim(ntn)=" + "'" + GridView1.SelectedValue + "'" Dim dr1 As OracleDataReader = cmd1.ExecuteReader() dr1.Read() dr1.Dispose() dr1.Close() cmd1.Dispose() conn1.Dispose() conn1.Close() End Sub The insert command execute perfectly if I remove the GridView1.SelectedValue. But it does not give the desired result as I want the value displayed in the data grid to be inserted only, before it is deleted. What happens in the above code is that data is deleted from the actual table, but nothing is inserted in the backup table described in the code above. I understand I need to write something else instead of GridView1.SelectedValue, but I can't think of anything else. Please help me with this. Thanks.

      J Offline
      J Offline
      janani13
      wrote on last edited by
      #2

      I think there may be some mistake in your query. Please refer Trigger concept to implement your desired results.

      H 1 Reply Last reply
      0
      • J janani13

        I think there may be some mistake in your query. Please refer Trigger concept to implement your desired results.

        H Offline
        H Offline
        Hammad Mansoor
        wrote on last edited by
        #3

        If there's mistake in query then how come it runs when i remove the GridView1.SelectedValue from it. I just need to get the value of the first column in the grid view. For that I need help. Thanks.

        S 1 Reply Last reply
        0
        • H Hammad Mansoor

          If there's mistake in query then how come it runs when i remove the GridView1.SelectedValue from it. I just need to get the value of the first column in the grid view. For that I need help. Thanks.

          S Offline
          S Offline
          Sneha Bisht
          wrote on last edited by
          #4

          protected void grid_category_RowDeleting(object sender, GridViewDeleteEventArgs e) { clsclass comfun = new clsclass(); // your main class or sqlcommand cmd; Label val = (Label)(your_grid.Rows[e.RowIndex].FindControl("lbl_id")); comfun.ExecuteNonQuery("delete from evaluation_category where evaluation_category_id=" + val.Text); Label val1 = (Label)(your_grid.Rows[e.RowIndex].FindControl("lbl_1")); Label val2 = (Label)(your_grid.Rows[e.RowIndex].FindControl("lbl_2")); Label val2 = (Label)(your_grid.Rows[e.RowIndex].FindControl("lbl_3")); cmd.executeNonQuery("insert into table values('"+ val1.text +','' + val2.text +'',''+ val3.text+'") // or done this query in storedprocedure // or both query can be done in same procedure // first remove value from first table then send thia to next one simple FillGrid(); // bind your grid } Try this.

          H 1 Reply Last reply
          0
          • S Sneha Bisht

            protected void grid_category_RowDeleting(object sender, GridViewDeleteEventArgs e) { clsclass comfun = new clsclass(); // your main class or sqlcommand cmd; Label val = (Label)(your_grid.Rows[e.RowIndex].FindControl("lbl_id")); comfun.ExecuteNonQuery("delete from evaluation_category where evaluation_category_id=" + val.Text); Label val1 = (Label)(your_grid.Rows[e.RowIndex].FindControl("lbl_1")); Label val2 = (Label)(your_grid.Rows[e.RowIndex].FindControl("lbl_2")); Label val2 = (Label)(your_grid.Rows[e.RowIndex].FindControl("lbl_3")); cmd.executeNonQuery("insert into table values('"+ val1.text +','' + val2.text +'',''+ val3.text+'") // or done this query in storedprocedure // or both query can be done in same procedure // first remove value from first table then send thia to next one simple FillGrid(); // bind your grid } Try this.

            H Offline
            H Offline
            Hammad Mansoor
            wrote on last edited by
            #5

            I tried your code and it's giving the following error Object reference not set to an instance of an object. It's coming in the line where I am using "val.text" in the insert statement.

            1 Reply Last reply
            0
            • H Hammad Mansoor

              Hi all I have a grid view which is used to delete the data in it. I want the data to be stored in another table before it is deleted from the actual table. The database is in Oracle. I am using the following code. Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) Handles GridView1.RowDeleting Dim oradb As String = "Data Source=(DESCRIPTION=" _ + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=Mahasilbkp.ltuisb.net)(PORT=1521)))" _ + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=db21a)));" _ + "User Id=;Password=;pooling=false;enlist=false;" Dim conn1 As New OracleConnection(oradb) conn1.Open() Dim cmd1 As New OracleCommand cmd1.Connection = conn1 GridView1.DataBind() cmd1.CommandText = "insert into uu.record_backup(ntn, name, status, enf, aud, sector, delete_user) select ntn, name, status, enf, aud, sector" + ",'" + Label5.Text + "'" + " " + "from uu.total_cases where trim(ntn)=" + "'" + GridView1.SelectedValue + "'" Dim dr1 As OracleDataReader = cmd1.ExecuteReader() dr1.Read() dr1.Dispose() dr1.Close() cmd1.Dispose() conn1.Dispose() conn1.Close() End Sub The insert command execute perfectly if I remove the GridView1.SelectedValue. But it does not give the desired result as I want the value displayed in the data grid to be inserted only, before it is deleted. What happens in the above code is that data is deleted from the actual table, but nothing is inserted in the backup table described in the code above. I understand I need to write something else instead of GridView1.SelectedValue, but I can't think of anything else. Please help me with this. Thanks.

              H Offline
              H Offline
              Hammad Mansoor
              wrote on last edited by
              #6

              Guys please help with putting GridView Value to a Label Text and my problem will be resolved. Thanks

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups