CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2009
    Posts
    16

    Question Input string was not in a correct format

    Hi all, need your help again..
    I have a trouble when running my application which is "Input string was not in a correct format". I imported my data from xls,
    Code:
    Dim cnstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & txtfName.Text & ";" & _
    "Extended Properties =""Excel 8.0;HDR=YES;IMEX=1;"""
    .
    .
    .
    
    Dim m1std As Decimal = 0
    .
    .
    
    While oledbdr.Read()
         If Not oledbdr.IsDBNull(25) Then
                  m1std = Decimal.Parse(oledbdr(25))
         Else
                  m1std = 0.0
         End If
    
    
    
    insertintosqlOPEX( mat1, m1std, mat1vol, mat1rpsat, mat1rp)
    
    end while
    
    
    
    
    
    Public Sub insertintosqlOPEX( ByVal mat1 As String, ByVal m1std As Decimal, ByVal mat1vol As Decimal, ByVal mat1rpsat As Decimal, ByVal mat1rp As Decimal)
    strSQL = "INSERT INTO " & tblname & "( Mat1, M1std, MAT1Vol,MAT1RpSat,MAT1Rp) VALUES ( @mat1, @m1std, @mat1vol,
    @mat1rpsat, @mat1rp )"
    Dim sqlcmd2 As New SqlCommand
    sqlcmd2.Connection = oconnection
    sqlcmd2.Parameters.Add("@Mat1", SqlDbType.VarChar, 255).Value = mat1
    
            Dim pm1std As New SqlParameter()
            With pm1std
                .Value = m1std
                .ParameterName = "@M1std"
                .SqlDbType = SqlDbType.Decimal
                .Precision = 15
                .Scale = 10
            End With
            sqlcmd2.Parameters.Add(pm1std)
    
    
    
            Dim pmat1vol As New SqlParameter()
            With pmat1vol
                .Value = mat1vol
                .ParameterName = "@mat1vol"
                .SqlDbType = SqlDbType.Decimal
                .Precision = 15
                .Scale = 5
            End With
            sqlcmd2.Parameters.Add(pmat1vol)
    
    
            Dim pmat1rpsat As New SqlParameter()
            With pmat1rpsat
                .Value = mat1rpsat
                .ParameterName = "@mat1rpsat"
                .SqlDbType = SqlDbType.Decimal
                .Precision = 15
                .Scale = 5
            End With
            sqlcmd2.Parameters.Add(pmat1rpsat)
    
            Dim pmat1rp As New SqlParameter()
            With pmat1rp
                .Value = mat1rp
                .ParameterName = "@mat1rp"
                .SqlDbType = SqlDbType.Decimal
                .Precision = 15
                .Scale = 5
            End With
            sqlcmd2.Parameters.Add(pmat1rp)
    
            sqlcmd2.CommandText = strSQL
            sqlcmd2.CommandType = CommandType.Text
            sqlcmd2.ExecuteNonQuery()
    From Xls file the value of m1std = 0.00002691, i have set the format into number with 10 decimal places, but i dont know how the data reader recognize the variable as string, i put value and show it to messagebox, the value become 2.691E-05. I think the .net thinks there is a character "E", and it recognize the variable become string. How to solve this?
    Thanks in advance
    Last edited by newcoder83; October 15th, 2009 at 01:55 AM. Reason: add CODE TAGS

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Input string was not in a correct format

    Go back and edit your post with:
    Code:
    '' CODE TAGS
    '     so things line up!
    and someone will show you where to use CAST()
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured