Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, January 12, 2015 11:36 AM
*Input string was not in a correct format. *
**Description: **An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
**Exception Details: **System.FormatException: Input string was not in a correct format.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
|
This is my Error ... when i save the data to database ...this occur showing me. but this event working my local system. but after upload the page an server the error showed me.
Please help any one...
Murali Pm
All replies (2)
Monday, January 12, 2015 11:53 AM âś…Answered
The error pretty much says what is happening, some of your strings are empty strings("") which it can't convert to an integer or double. My guess it goes wrong here
If Convert.ToInt32(Refdt.Rows(i)("Stock").ToString()) = 0 Then
where Refdt.Rows(i)("Stock").ToString() is sometimes an empty string
or one of these is an empty string
dr("Qty") = (Refdt.Rows(i)("Qty").ToString())
dr("Price") = (Refdt.Rows(i)("Price").ToString())
My advice is debug step through your code and see which conversion is the culprit and adjust accordingly
Monday, January 12, 2015 11:40 AM
THIS IS MY CODE ...
#Region "btnAdd_Click"
Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Try
Dim connString As String = ""
Dim fileName As String = String.Empty
'System.IO.File.Delete(Server.MapPath("~/DetailedDrawing/") + fileName)
Dim strFileType As String = Path.GetExtension(ExcelFileUpload.FileName).ToLower()
Dim path__1 As String = ExcelFileUpload.PostedFile.FileName
If path__1 = "" Then
Dim Alertstr As String = "Please upload excel sheet."
bllCommon.MessageBoxError(Me, Alertstr)
Exit Sub
End If
Dim str() As String = Split(path__1, ".")
If LCase(str(1)) = "xlsx" Or LCase(str(1)) = "xls" Then
Else
Dim Alertstr As String = LCase(str(1)) + " File Format Not Allow."
bllCommon.MessageBoxError(Me, Alertstr)
Exit Sub
End If
If ExcelFileUpload.FileName.Length > 0 Then
fileName = Path.GetFileName(ExcelFileUpload.PostedFile.FileName)
ExcelFileUpload.PostedFile.SaveAs((Server.MapPath("~/BOMExcelFile/") + fileName))
End If
Dim objBl As New boBOM
Dim Exceldt As New DataTable
Exceldt = ReadExcelField(Server.MapPath("~/BOMExcelFile/" + path__1))
If Exceldt.Rows.Count < 0 Then Exit Sub
grdView.DataSource = libGrid.RemoveDuplicateRows(Exceldt, "PartNo")
grdView.DataBind()
result = Exceldt.Rows.Count
If Convert.ToInt32(result) > 1 Then
bllCommon.MessageBoxSuccess(Me, libmsg.ExcelUpload)
ViewState("ExcelDt") = Exceldt
Else
bllCommon.MessageBoxError(Me, result)
End If
Catch ex As Exception
Throw ex
End Try
End Sub
'Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
' If txtQty.Text = String.Empty Then Exit Sub
' ' Modified by murali on 28/12/2014 without Stock Item'
' 'If Val(txtQty.Text) > Val(hdnStock.Value) Or Val(hdnStock.Value) = 0 Then
' 'ClientScript.RegisterStartupScript(Me.GetType(), "myalert", "alert('Insufficient Stock!');", True)
' ' Dim dtItem1 As DataTable = bllItem.GetItemAll()
' ' LibCommon.BindDropdownlist(ddlItem, dtItem1, "ItemWithCode", "ItemId", True)
' ' ddlItem.SelectedIndex = 0
' ' txtQty.Text = String.Empty
' ' Exit Sub
' 'End If
' ConvertGridToDatatable()
' Dim dtTemp As DataTable = CType(ViewState("dtTempDtl"), DataTable)
' grvBOM.AutoGenerateColumns = False
' Dim i As Integer
' For i = 0 To dtTemp.Rows.Count - 1
' If LibCommon.ConvertStringToDouble(ddlItem.SelectedValue) = LibCommon.ConvertStringToDouble(dtTemp.Rows(i)("ItemID").ToString) Then
' bllCommon.MessageBoxError(Me, libmsg.Duplicate)
' Exit Sub
' End If
' Next
' Dim dtItem As DataTable = bllItem.GetItem(ddlItem.SelectedValue)
' If dtItem.Rows.Count > 0 Then
' Dim dr As DataRow = dtTemp.NewRow()
' dr("ItemId") = LibCommon.ConvertStringToDouble(ddlItem.SelectedValue)
' dr("Itemcode") = dtItem.Rows(0)("Itemcode").ToString()
' dr("ItemName") = dtItem.Rows(0)("ItemName").ToString()
' dr("Make") = dtItem.Rows(0)("Make").ToString()
' dr("uom") = dtItem.Rows(0)("uom").ToString()
' dr("RequestedQty") = LibCommon.ConvertStringToDouble(txtQty.Text.Trim)
' dr("Price") = 0
' dr("Stock") = hdnStock.Value
' dtTemp.Rows.InsertAt(dr, dtTemp.Rows.Count)
' End If
' ViewState("dtTempDtl") = dtTemp
' BindGridView()
' ddlItem.SelectedIndex = 0
' txtQty.Text = String.Empty
'End Sub
#End Region
#Region "ItemDtl"
Public Function ItemDtl() As DataTable
Dim ItemIdDuplicateCount, ItemIdCount As New DataTable
With grdView
Dim GrdRowcount As Int32 = .Rows.Count()
ItemIdCount.Rows.Clear()
ItemIdDuplicateCount.Rows.Clear()
For i = 0 To GrdRowcount - 2
If (grdView.Rows(i).Cells(0).Text) <> "" And (.Rows(i).Cells(1).Text.Trim) <> "" Then
Dim strQry As String = "exec Usp_ItemIdAndStockDtl '" & .Rows(i).Cells(0).Text.Trim & "','" & .Rows(i).Cells(1).Text.Trim & "' ,' ','" & .Rows(i).Cells(2).Text & "'," & LibCommon.GetCompanyId & ",'" & (ddlBranch.SelectedValue) & "'," & .Rows(i).Cells(3).Text & "," & Val(.Rows(i).Cells(5).Text.Trim) & ",'" & Convert.ToDateTime(.Rows(i).Cells(6).Text) & "' "
ItemIdDuplicateCount.Merge(dbConnect.SelectQry(strQry))
End If
Next
ItemIdCount = libGrid.RemoveDuplicateRows(ItemIdDuplicateCount, "ItemId")
End With
Return ItemIdCount
End Function
#End Region
#Region "PurchaseRequisitionSave"
Public Sub FnPurchaseRequisitonSave(ByVal Refdt As DataTable)
Try
Dim RefdtCOUNT As Int32 = Refdt.Rows.Count()
Dim dt, dt2 As New DataTable
Dim dr As DataRow
dt.Columns.Add("ItemId", GetType(Integer))
dt.Columns.Add("Spec", GetType(String))
dt.Columns.Add("Qty", GetType(Double))
dt.Columns.Add("Price", GetType(Double))
dt.Columns.Add("RequiredDate", GetType(String))
dt.Columns.Add("RequiredFor", GetType(String))
dt.Columns.Add("RequiredBy", GetType(String))
dt.Columns.Add("SuggSupplierId", GetType(Integer))
dt.Columns.Add("Remarks", GetType(String))
dr = dt.NewRow
For i = 0 To RefdtCOUNT - 1
If Convert.ToInt32(Refdt.Rows(i)("Stock").ToString()) = 0 Then
dr("ItemId") = (Refdt.Rows(i)("ItemId"))
dr("Spec") = ""
dr("Qty") = (Refdt.Rows(i)("Qty").ToString())
dr("Price") = (Refdt.Rows(i)("Price").ToString())
dr("RequiredDate") = (Refdt.Rows(i)("RequiredDate").ToString())
dr("RequiredFor") = ""
dr("RequiredBy") = LibCommon.ConvertStringToDouble(dbConnect.ExecuteScalar("select isnull(max(bomid),0) from tbl_bom where CompanyID = " & LibCommon.GetCompanyId & " and BranchId =" & LibCommon.ConvertStringToInteger(ddlBranch.SelectedValue) & ""))
dr("SuggSupplierId") = 0 'hdnBOMid.Value
dr("Remarks") = ""
dt.Rows.Add(dr)
dt2.Merge(dt)
dt.Rows.Clear()
End If
Next
Dim objPR As New boPR
Dim parameter As SqlParameter() = New SqlParameter(6) {}
objPR.CompanyId = LibCommon.GetCompanyId
objPR.DepartmentId = LibCommon.ConvertStringToDouble(ddlDepartment.SelectedValue)
objPR.BranchId = LibCommon.ConvertStringToDouble(ddlBranch.SelectedValue)
objPR.FinYear = LibCommon.GetFinYearId
objPR.CreatedBy = LibCommon.GetUserID
objPR.ProjectId = LibCommon.ConvertStringToDouble(ddlProject.SelectedValue)
objPR.PRDtl = dt2
parameter(0) = New SqlParameter("@CompanyId", objPR.CompanyId)
parameter(1) = New SqlParameter("@DepartmentId", objPR.DepartmentId)
parameter(2) = New SqlParameter("@BranchId", objPR.BranchId)
parameter(3) = New SqlParameter("@FinYearId", objPR.FinYear)
parameter(4) = New SqlParameter("@CreatedBy", objPR.CreatedBy)
parameter(5) = New SqlParameter("@ProjectId", objPR.ProjectId)
parameter(6) = New SqlParameter("@PRDtl", objPR.PRDtl)
' Dim Qrystr As String = "exec Usp_BOM_To_PRSave " & objPR.CompanyId & "," & objPR.DepartmentId & "," & objPR.BranchId & "," & objPR.FinYear & "," & objPR.CreatedBy & " ," & objPR.ProjectId & " ,'" & Convert.ToString(objPR.PRDtl) & "' "
dbConnect.ExecuteProcedure("[Usp_BOM_To_PRSave]", parameter)
Catch ex As Exception
Throw ex
End Try
End Sub
#End Region
#Region "btnSave_Click"
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
'If 1 = 1 Then ClientScript.RegisterStartupScript(Me.GetType(), "myalert", "alert('Process going on..');", True) :Exit Sub
Dim objBOM As boBOM = New boBOM()
ConvertGridToDatatable()
Dim dtBOMDtl As DataTable = CType(ViewState("dtTempDtl"), DataTable)
Dim columns As DataColumnCollection = dtBOMDtl.Columns
columns.Remove("Itemcode")
columns.Remove("ItemName")
columns.Remove("Make")
columns.Remove("uom")
objBOM.BOMDtl = dtBOMDtl
If ViewState("mode").ToString() = "New" Then
objBOM.Mode = "new"
Else
objBOM.Mode = "edit"
End If
Dim pid As Integer
pid = dbConnect.ExecuteScalar("SELECT ProjectID FROM tbl_Project where CompanyID = " & LibCommon.GetCompanyId & " and ProjectName ='" & ddlProject.SelectedItem.Text & "'")
objBOM.BOMId = LibCommon.ConvertStringToDouble(hdnBOMid.Value)
objBOM.BOMNo = txtBOMNo.Text
objBOM.CompanyId = LibCommon.GetCompanyId
objBOM.BOMDate = txtBOMDate.Text
objBOM.ProjectId = LibCommon.ConvertStringToDouble(pid)
objBOM.PreparedBy = txtPreparedBy.Text
objBOM.ReceivedBy = txtReceivcedBy.Text
objBOM.CreatedBy = LibCommon.GetUserID
objBOM.DepartmentId = LibCommon.ConvertStringToDouble(ddlDepartment.SelectedValue)
objBOM.BranchId = LibCommon.ConvertStringToDouble(ddlBranch.SelectedValue)
objBOM.CustomerId = LibCommon.ConvertStringToDouble(ddlCustomer.SelectedValue)
objBOM.EnquiryId = LibCommon.ConvertStringToDouble(hdnEnquiryId.Value)
objBOM.EnquiryDate = txtEnquiryDate.Text
Dim Itemdt As DataTable
If ViewState("mode").ToString() = "New" Then
Itemdt = ItemDtl()
objBOM.BOMDtl = Itemdt 'dtBOMDtl
result = bllBOM.SaveBOM(objBOM)
FnPurchaseRequisitonSave(Itemdt)
Else
objBOM.BOMDtl = OneDataColumnAddInDataTable(dtBOMDtl)
result = bllBOM.SaveBOM(objBOM)
End If
If result = "1" Then
bllCommon.MessageBoxSuccess(Me, libmsg.Saved)
ResetForm()
Else
bllCommon.MessageBoxError(Me, result)
End If
End Sub
#End Region
Murali Pm