Results 1 to 7 of 7

Thread: Problem with Datagridview in vs2012

  1. #1

    Thread Starter
    Addicted Member frangine's Avatar
    Join Date
    Jan 2014
    Posts
    152

    Problem with Datagridview in vs2012

    hello guy'zz (^____^)

    i have my datagridview to compute the value of each columns:
    but when i execute this...
    Code:
    For i As Integer = 0 To Me.DataGridView1.RowCount - 1
    
             Dim bwsw As Double = Me.DataGridView1.Rows(i).Cells("BW").Value() - Me.DataGridView1.Rows(i).Cells("SW").Value()
    
                    Me.DataGridView1.Rows(i).Cells("BSR").Value() = (bwsw - ((Me.DataGridView1.Rows(i).Cells("FL").Value() * bwsw) / 100)) / 13.5
                Me.DataGridView1.Rows(i).Cells("Bunches/has/yr").Value() = Me.DataGridView1.Rows(i).Cells("Population/has").Value() * Me.DataGridView1.Rows(i).Cells("Turnover").Value()
    
      Me.DataGridView1.Rows(i).Cells("Boxes/has/yr").Value() = Me.DataGridView1.Rows(i).Cells("BSR").Value() * Me.DataGridView1.Rows(i).Cells("Bunches/has/yr").Value()
    
            Next
    then Error show : (object of type 'System.Double' cannot be converted to type 'System.Decimal')

    help me guy'z thanks...!!!

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,624

    Re: Problem with Datagridview in vs2012

    which line do you get the error from when you step through and debug?
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  3. #3

    Thread Starter
    Addicted Member frangine's Avatar
    Join Date
    Jan 2014
    Posts
    152

    Re: Problem with Datagridview in vs2012

    this line...
    Code:
    Me.DataGridView1.Rows(i).Cells("Boxes/has/yr").Value() = Me.DataGridView1.Rows(i).Cells("BSR").Value() * Me.DataGridView1.Rows(i).Cells("Bunches/has/yr").Value()

  4. #4
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,624

    Re: Problem with Datagridview in vs2012

    Ok so you have a type mismatch;

    The Cell / Column you are trying to assign that number to is of type Decimal but the value you are trying to assign is of type Double.

    Try this -

    Code:
    Me.DataGridView1.Rows(i).Cells("Boxes/has/yr").Value() = Convert.ToDecimal(Me.DataGridView1.Rows(i).Cells("BSR").Value() * Me.DataGridView1.Rows(i).Cells("Bunches/has/yr").Value())
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  5. #5

    Thread Starter
    Addicted Member frangine's Avatar
    Join Date
    Jan 2014
    Posts
    152

    Re: Problem with Datagridview in vs2012

    A NEW PROBLEM IN DATAGRIDVIEW....
    =>> ERROR: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 23 ("@variance"): The supplied value is not a valid instance of data type float. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision.

    --->>in my update button...my code
    Code:
       Private Sub btnupdate_Click(sender As Object, e As EventArgs) Handles btnupdate.Click
    
    
            acon = GetArvinConnect()
    
    
            '   Try
    
            acon.Open()
    
            cmd2 = New SqlCommand("update_RvsP", acon)
    
            With cmd2
    
    
                .CommandType = CommandType.StoredProcedure
    
                .Parameters.AddWithValue("@year", SqlDbType.Int)
                .Parameters.AddWithValue("@month", SqlDbType.Int)
                .Parameters.AddWithValue("@company", SqlDbType.Int)
                .Parameters.AddWithValue("@farm", SqlDbType.NVarChar)
                .Parameters.AddWithValue("@parcel", SqlDbType.NVarChar)
                .Parameters.AddWithValue("@layout", SqlDbType.NVarChar)
                .Parameters.AddWithValue("@area", SqlDbType.Decimal)
                .Parameters.AddWithValue("@scI", SqlDbType.Decimal)
                .Parameters.AddWithValue("@scII", SqlDbType.Decimal)
                .Parameters.AddWithValue("@scIII", SqlDbType.Decimal)
                .Parameters.AddWithValue("@scIV", SqlDbType.Decimal)
                .Parameters.AddWithValue("@r_boxes_h_y", SqlDbType.Decimal)
                .Parameters.AddWithValue("@r_boxes_y", SqlDbType.Decimal)
                .Parameters.AddWithValue("@bw", SqlDbType.Decimal)
                .Parameters.AddWithValue("@fl", SqlDbType.Decimal)
                .Parameters.AddWithValue("@sw", SqlDbType.Decimal)
                .Parameters.AddWithValue("@bsr", SqlDbType.Decimal)
                .Parameters.AddWithValue("@population", SqlDbType.Decimal)
                .Parameters.AddWithValue("@turnover", SqlDbType.Decimal)
                .Parameters.AddWithValue("@bunches_h_y", SqlDbType.Decimal)
                .Parameters.AddWithValue("@p_boxes_h_y", SqlDbType.Decimal)
                .Parameters.AddWithValue("@p_boxes_y", SqlDbType.Decimal)
                .Parameters.AddWithValue("@variance", SqlDbType.Decimal)
                .Parameters.AddWithValue("@target_fl", SqlDbType.Decimal)
                .Parameters.AddWithValue("@diff_fl", SqlDbType.Decimal)
    
    
                For i As Integer = 0 To Me.DataGridView1.Rows.Count - 1
    
                    .Parameters("@year").Value = Me.DataGridView1.Rows(i).Cells("Year").Value
                    .Parameters("@month").Value = Me.DataGridView1.Rows(i).Cells("Month").Value
                    .Parameters("@company").Value = Me.DataGridView1.Rows(i).Cells("Company").Value
                    .Parameters("@farm").Value = Me.DataGridView1.Rows(i).Cells("Farm").Value
                    .Parameters("@parcel").Value = Me.DataGridView1.Rows(i).Cells("Parcel").Value
                    .Parameters("@layout").Value = Me.DataGridView1.Rows(i).Cells("Layout").Value
                    .Parameters("@area").Value = Me.DataGridView1.Rows(i).Cells("Area").Value
                    .Parameters("@scI").Value = Me.DataGridView1.Rows(i).Cells("SC-I-(has)").Value
                    .Parameters("@scII").Value = Me.DataGridView1.Rows(i).Cells("SC-II-(has)").Value
                    .Parameters("@scIII").Value = Me.DataGridView1.Rows(i).Cells("SC-III-(has)").Value
                    .Parameters("@scIV").Value = Me.DataGridView1.Rows(i).Cells("SC-IV-(has)").Value
                    .Parameters("@r_boxes_h_y").Value = Me.DataGridView1.Rows(i).Cells("Research Boxes/has/yr").Value
                    .Parameters("@r_boxes_y").Value = Me.DataGridView1.Rows(i).Cells("Research Boxes/yr").Value
                    .Parameters("@bw").Value = Me.DataGridView1.Rows(i).Cells("BW").Value
                    .Parameters("@fl").Value = Me.DataGridView1.Rows(i).Cells("FL").Value
                    .Parameters("@sw").Value = Me.DataGridView1.Rows(i).Cells("SW").Value
                    .Parameters("@bsr").Value = Me.DataGridView1.Rows(i).Cells("BSR").Value
                    .Parameters("@population").Value = Me.DataGridView1.Rows(i).Cells("Population/has").Value
                    .Parameters("@turnover").Value = Me.DataGridView1.Rows(i).Cells("Turnover").Value
                    .Parameters("@bunches_h_y").Value = Me.DataGridView1.Rows(i).Cells("Bunches/has/yr").Value
                    .Parameters("@p_boxes_h_y").Value = Me.DataGridView1.Rows(i).Cells("Production Boxes/has/yr").Value
                    .Parameters("@p_boxes_y").Value = Me.DataGridView1.Rows(i).Cells("Production Boxes/yr").Value
                    .Parameters("@variance").Value = Me.DataGridView1.Rows(i).Cells("% Variance (Boxes/Has/Yr)").Value
                    .Parameters("@target_fl").Value = Me.DataGridView1.Rows(i).Cells("Target % FL").Value
                    .Parameters("@diff_fl").Value = Me.DataGridView1.Rows(i).Cells("Difference FL").Value
    
    
    
                    .ExecuteNonQuery()
    
    
    
                Next
    
                MsgBox("Successfully  Updated")
    
            End With
    
            acon.Close()
    
            'Catch ex As Exception
            'MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            ' End Try
    
        End Sub
    -> see below...i think because of the -infinity value

    ====>>help me please thank you
    Attached Images Attached Images  

  6. #6

    Thread Starter
    Addicted Member frangine's Avatar
    Join Date
    Jan 2014
    Posts
    152

    Re: Problem with Datagridview in vs2012

    this columns has its computaion:
    Code:
      Dim ans As Double = Me.DataGridView1.Rows(i).Cells("Production Boxes/has/yr").Value() - Me.DataGridView1.Rows(i).Cells("Research Boxes/has/yr").Value()
                    Me.DataGridView1.Rows(i).Cells("% Variance (Boxes/Has/Yr)").Value() = ((ans) / Me.DataGridView1.Rows(i).Cells("Production Boxes/has/yr").Value()) * 100
    
                    Me.DataGridView1.Rows(i).Cells("Target % FL").Value() = (1 - ((Me.DataGridView1.Rows(i).Cells("Research Boxes/has/yr").Value() * 13.5) / (Me.DataGridView1.Rows(i).Cells("Population/has").Value() * Me.DataGridView1.Rows(i).Cells("Turnover").Value() * (Me.DataGridView1.Rows(i).Cells("BW").Value() - Me.DataGridView1.Rows(i).Cells("SW").Value())))) * 100
    please help me .....

  7. #7
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,554

    Re: Problem with Datagridview in vs2012

    Quote Originally Posted by frangine View Post
    this columns has its computaion:
    Code:
      Dim ans As Double = Me.DataGridView1.Rows(i).Cells("Production Boxes/has/yr").Value() - Me.DataGridView1.Rows(i).Cells("Research Boxes/has/yr").Value()
                    Me.DataGridView1.Rows(i).Cells("% Variance (Boxes/Has/Yr)").Value() = ((ans) / Me.DataGridView1.Rows(i).Cells("Production Boxes/has/yr").Value()) * 100
    
                    Me.DataGridView1.Rows(i).Cells("Target % FL").Value() = (1 - ((Me.DataGridView1.Rows(i).Cells("Research Boxes/has/yr").Value() * 13.5) / (Me.DataGridView1.Rows(i).Cells("Population/has").Value() * Me.DataGridView1.Rows(i).Cells("Turnover").Value() * (Me.DataGridView1.Rows(i).Cells("BW").Value() - Me.DataGridView1.Rows(i).Cells("SW").Value())))) * 100
    please help me .....
    What's the question?

    I can see in post #5 that the word "infinity" is found in some of the columns. These columns would have to have a data type of string. You would have to convert this column value to the proper data type before you can preform any calculations.

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