Ok guys "GridView1.Rows(e.RowIndex).Cells("NTN").Value" gives error on the "value" as it does not recognize it. So I used "GridView1.Rows(e.RowIndex).Cells("NTN").Text". Now I am getting the following error System.FormatException: Input string was not in a correct format. it is coming on this line. Line 54: 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.Rows(e.RowIndex).Cells("NTN").Text + "'" Please help me where I am making mistake in the above line. Thanks for your help.
Hammad Mansoor
Posts
-
Please help with Inserting value from DataGrid in Database Table -
Please help with Inserting value from DataGrid in Database TableOk guys i tried that, but I am still getting that "Object reference not set to an instance of an object" on the insert statement. Just want to clarify that "NTN" in lblNTN = DirectCast((GridView1.Rows(e.RowIndex).FindControl("NTN")), Label) is the name of the column of the Data Grid from which I want the data to be retrieved. Am I doing it the correct way? If not please help with this. Thanks.
-
Please help with Inserting value from DataGrid in Database Tableval is a declared label to store the data from the NTN column of the grid Dim val As Label = DirectCast((GridView1.Rows(e.RowIndex).FindControl("NTN")), Label) Thanks.
-
Please help with Inserting value from DataGrid in Database TableHi all I'm trying to get a value of a column in DataGrid and insert it in Oracle Table. Below is my 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=" + Label5.Text + ";Password=;pooling=false;enlist=false;" Dim conn1 As New OracleConnection(oradb) conn1.Open() Dim cmd1 As New OracleCommand cmd1.Connection = conn1 GridView1.DataBind() Dim val As Label = DirectCast((GridView1.Rows(e.RowIndex).FindControl("NTN")), Label) 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)='" + val.Text.ToString + "'" Dim dr1 As OracleDataReader = cmd1.ExecuteReader() dr1.Read() dr1.Dispose() dr1.Close() cmd1.Dispose() conn1.Dispose() conn1.Close() End Sub When I click on Delete it gives the following error: Object reference not set to an instance of an object. Source Error: Line 49: 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)='" + val.Text + "'" If I remove the "val.Text" from the above code then it works, but obviously the results are not as I desire. Please help me with this. Thanks.
-
Please help with inserting GridView Values in oracle tableGuys please help with putting GridView Value to a Label Text and my problem will be resolved. Thanks
-
Please help with inserting GridView Values in oracle tableI 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.
-
Please help with inserting GridView Values in oracle tableIf 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.
-
Please help with inserting GridView Values in oracle tableHi 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.
-
ASP.NET not executing Oracle queryHi all When I execute this query in Oracle I get perfect results. 1. SELECT * FROM TOTAL_CASES 2. WHERE (TRIM("NTN") = TRIM(:NTN) 3. OR '%'||upper("NAME")||'%' LIKE '%'||upper(:NAME)||'%') 4. AND (upper(TRIM("STATUS")) LIKE nvl(upper(TRIM(:STATUS)),'%'||''||'%')) It means that if :STATUS is NULL then give all results matching step 3 or 4. If there is a value for :STATUS then also filter results according to that value. This query gives accurate results when executed in SQL. However, I also use this to populate a Data Grid in ASP.NET. When STATUS is NULL in ASP.NET, the Data Grid shows no results. However, when I select value for the STATUS, then it shows results according to the value chosen for STATUS. Please help me as to how to populate Data Grid when I select no value for STATUS. Thanks. Hammad
-
Please help with Data Grid export problemThanks a lot Kumar. It worked like a magic :) Thanks once again. Hammad
-
Please help with Data Grid export problemOk I have changed my code. I think it should work, But it isn't. Any suggestions? Please check my code below. Imports System.Data Imports System.IO Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Dim style As String = "<style> .text { mso-number-format:\@; } </style> " Response.ClearContent() Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls") Response.ContentType = "application/excel" GridView1.AllowPaging = False Dim sw As New StringWriter() Dim htw As New HtmlTextWriter(sw) GridView1.DataBind() GridView1.RenderControl(htw) 'Style is added dynamically Response.Write(style) Response.Write(sw.ToString()) Response.End() End Sub Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then e.Row.Cells(0).Attributes.Add("class", "text") End If End Sub End Class
-
Please help with Data Grid export problemI am using the following code to export Data Grid to excel. It works fine, except that it misses the leading '0's in the first column. For example, I have data in first column like '0034566'. When it exports to excel, the data is shown as '34566'. I have tried many things but it's still not working. Please help. Imports System.Data Imports System.IO Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition", "attachment;filename=SearchDownload.xls") Response.Charset = "" Me.EnableViewState = False GridView1.AllowPaging = False Dim dtSupplier As DataTable = DirectCast(ViewState("dtSupplier"), DataTable) GridView1.DataSource = dtSupplier GridView1.DataBind() Dim stringWrite As New System.IO.StringWriter() Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite) Dim StyleAsText As String = "<style> .StyleAsText{ mso-number-format:\@;} </style>" GridView1.RenderControl(htmlWrite) 'Response.Write(strStyle) 'Response.Write(stringWrite.ToString()) Response.Write(StyleAsText + stringWrite.ToString()) Response.End() End Sub Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub End Class