Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bubberz
Constraint Violating Yak Guru
289 Posts |
Posted - 2006-08-17 : 16:02:10
|
With only one record on my 2nd page in my datagrid, when I go from page 2 to page 1 in my Datagrid (ASP.NET v1.1), I get:Input string was not in a correct format. [FormatException: Input string was not in a correct format.] Microsoft.VisualBasic.CompilerServices.DoubleType.Parse(String Value, NumberFormatInfo NumberFormat) +193 Microsoft.VisualBasic.CompilerServices.IntegerType.FromString(String Value) +92[InvalidCastException: Cast from string "" to type 'Integer' is not valid.] Microsoft.VisualBasic.CompilerServices.IntegerType.FromString(String Value) +206 Work_PackageVBConvert_P3E.SARESTableSubform.DataGrid1_DeleteCommand(Object source, DataGridCommandEventArgs e) +185 System.Web.UI.WebControls.DataGrid.OnDeleteCommand(DataGridCommandEventArgs e) +109 System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +589 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26 System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +106 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26 System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138 System.Web.UI.Page.ProcessRequestMain() +1292****************************************************************I have no idea what's going on or why this is happening. If I add another record to my datagrid, and now I have two rows on my second page, I can go to the first page successfully.The PageIndexChanged routine is simply:DataGrid1.CurrentPageIndex = e.NewPageIndexCall DG()Any ideas?Thanks! |
|
elwoos
Master Smack Fu Yak Hacker
2052 Posts |
Posted - 2006-08-18 : 09:56:16
|
Clutching at straws a bit but check your data. It looks as though there may be a record that has a null or an empty string where an integer is expected. If you change that the issue may dissapearsteve-----------Don't worry head. The computer will do all the thinking from now on. |
 |
|
bubberz
Constraint Violating Yak Guru
289 Posts |
Posted - 2006-08-18 : 10:05:02
|
elwoos!thanks for the reply.When I turned on debug, the error was in my deletecommand on the linemyCommand.Parameters(0).Value = CType(e.Item.Cells(15).Text, Integer)......even though that's the PK for the table:Dim deleteCmd As String = "usp_DeleteFromSARes" Dim sCon1 As New SqlConnection sCon1.ConnectionString = Session("DBDDL") Try sCon1.Open() Dim myCommand As SqlCommand = New SqlCommand(deleteCmd, sCon1) myCommand.CommandType = CommandType.StoredProcedure myCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@intUID", System.Data.SqlDbType.Int, 4)) myCommand.Parameters(0).Value = CType(e.Item.Cells(15).Text, Integer) myCommand.ExecuteNonQuery() sCon1.Close() 'This is to control if the items deleted were on the last page If DataGrid1.Items.Count Mod DataGrid1.PageSize = 1 And _ DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1 And _ DataGrid1.CurrentPageIndex <> 0 Then DataGrid1.CurrentPageIndex = DataGrid1.CurrentPageIndex - 1 End If Call BuildMainDG() Catch ex As Exception lblStatus.Text = "Line 480 DG Delete Error: " & ex.Message Finally sCon1.Close() End TryThe error here gives cast from type string "" to type integer not valid. |
 |
|
bubberz
Constraint Violating Yak Guru
289 Posts |
Posted - 2006-08-18 : 15:11:22
|
The following is a fix I was able to do. It's the best solution I've come up with in order for the user not to lose data from the UI.Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand If intDisable = 1 Then Exit Sub 'Use this to enable/disable Edit/Update/Delete for dgrids based on Rev# 'Un-Hide the "Locate" and "ChkCode" columns DataGrid1.Columns(0).Visible = True DataGrid1.Columns(3).Visible = True Dim deleteCmd As String = "usp_DeleteFromSARes" Dim sCon1 As New SqlConnection sCon1.ConnectionString = Session("DBDDL") Try sCon1.Open() Dim myCommand As SqlCommand = New SqlCommand(deleteCmd, sCon1) myCommand.CommandType = CommandType.StoredProcedure myCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@intUID", System.Data.SqlDbType.Int, 4)) Dim strDGUID As String = e.Item.Cells(15).Text.ToString myCommand.Parameters(0).Value = CType(e.Item.Cells(15).Text.ToString, Integer) myCommand.ExecuteNonQuery() sCon1.Close() DataGrid1.EditItemIndex = -1 Call BuildMainDG() 'DataGrid1.EditItemIndex = -1 'DataGrid1.DataBind() Catch ex As InvalidCastException 'This exception is for paging from 2nd to 1st page w/ 1 record on page2 lblStatus.Text = "481 Null RefEx:" Call BuildMainDG() Catch ex As Exception lblStatus.Text = "484 DG Error: " & ex.Message Call BuildMainDG() Finally sCon1.Close() 'This is to control if the items deleted were on the last page If DataGrid1.Items.Count Mod DataGrid1.PageSize = 1 And _ DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1 And _ DataGrid1.CurrentPageIndex <> 0 Then DataGrid1.CurrentPageIndex = DataGrid1.CurrentPageIndex - 1 Else DataGrid1.CurrentPageIndex = DataGrid1.CurrentPageIndex End If End Try |
 |
|
|
|
|
|
|