Question: I have 1 DataGridView with 3 columns, 1 button named as **AssignID**, 1 Database with **EmployeeList** Table.

Columns of Datagridview

1. Column 1 = EmployeeID
2. Column 2 = EmployeeName
3. Column 3 = Department

I'm pasting the data of **EmployeeName** and **Department** from excel into DataGridView leaving column 1 as blank. My problem is how to automatically assign the **EmployeeID** per Employee in the DataGridView when I press the button **AssignID**. The last **IDNumber** in the database is 10000.

Appreciate your help. Im still learning vb.net. Thanks in Advance.

Im using below code:

```
Private Sub AssignID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AssignID.Click
    Dim Dbcon As New OleDbConnection(connStr)

    Dbcon.Open()

    Dim query As String
    Dim dbup As New OleDbCommand
    Try

        query = "SELECT Max (EmployeeID) from EmployeeList"
        dbup = New OleDbCommand(query, Dbcon)

        Dim EmpID As Integer

        EmpID = dbup.ExecuteScalar

        Dim i2 As Integer
        i2 = Me.NewEmployeesDataGridview.CurrentRow.Index

        NewEmployeesDataGridview.Item(0, i2).Value() = EmpID

        For x As Integer = 0 To NewEmployeesDataGridview.Rows.Count - 2
            NewEmployeesDataGridview.Rows(x).Cells(0).Value = NewEmployeesDataGridview.Rows(0).Cells(0).Value + 1

        Next

        NewEmployeesDataGridview.AllowUserToAddRows = False

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

```

Answer: 
Paraphrased from Eric Lippert's blog:

<http://blogs.msdn.com/b/ericlippert/archive/2009/03/19/representation-and-identity.aspx>

The C# cast operator is used for identity preserving conversions (e.g. interpret this reference to base class as a reference to derived class) and identity destroying conversions (e.g. convert this `int` to a `double`). A single use of the cast operator is only allowed to invoke *one* of these.

Since you boxed an `int`, the only thing that the `int` may be unboxed to is `int` (this is an identity preserving case). Once it is unboxed to `int`, it may be converted (in the identity destroying case) to `bool`.

That is:

```
int iii = 123;
object ooo = iii;            // Box the int
bool bbb = (bool) iii;       // Perfectly legal
bool jjj = (bool) (int) ooo; // Perfectly legal
bool kkk = (bool) ooo;       // Invalid cast exception

```
use this code for convert object to Boolean

```
 var t = propInfo.GetValue(item, null);
bool state = Convert.ToBoolean(t);

```