Please help with inserting GridView Values in oracle table
-
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.
-
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.
-
I think there may be some mistake in your query. Please refer Trigger concept to implement your desired results.
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.
-
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.
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.
-
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.
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.
-
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.
Guys please help with putting GridView Value to a Label Text and my problem will be resolved. Thanks