Hi,

this will work in Edit button click,Getting values from combobox and given input to query.Oprdgv is my Datagrid.
I got the error Like,

"unable to cast the type 'system.int32' to type 'system.data.datatable"

Private Sub EditButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditButton.Click

        Dim mcode As String = MccodeCombo.SelectedValue
        Dim pcode As String = ProdCombo.SelectedValue

        OprDgv.Columns.Add("Prodcd", "Prodcode")
        OprDgv.Columns.Add("Mccode", "Mccode")
        OprDgv.Columns.Add("Oprno", "Oprno")
        OprDgv.Columns.Add("OPname", "Oprname")
        OprDgv.Columns.Add("Stime", "Settime")
        OprDgv.Columns.Add("Stdpc", "StdPc")
        OprDgv.Columns.Add("Ratepc", "Ratepc")
        OprDgv.Columns(0).Width = 50
        con = New SqlConnection(constr)
        cmdstr = "Select * from Operations where Mccode='" & mcode & "'and Prodcode='" & pcode & "'"
        dt = DataManager.ExecuteNonQuery(constr, cmdstr)
        Dim rc As Integer = dt.Rows.Count
        If (rc > 0) Then

            For i = 0 To rc - 1
                OprDgv.Rows.Add()
                OprDgv.Item(0, i).Value = dt.Rows(i).Item("Prodcode")
                OprDgv.Item(1, i).Value = dt.Rows(i).Item("Mccode")
                OprDgv.Item(2, i).Value = dt.Rows(i).Item("Oprno")
                OprDgv.Item(3, i).Value = dt.Rows(i).Item("Oprname")
                OprDgv.Item(4, i).Value = dt.Rows(i).Item("Settime")
                OprDgv.Item(5, i).Value = dt.Rows(i).Item("Stdpcshift")
                OprDgv.Item(6, i).Value = dt.Rows(i).Item("Ratepc")


            Next
        Else
            MessageBox.Show("No Record Found")
        End If
    End Sub

At which line are u getting the error?

You have to know that dataTable by default has object type. No string ot integer.
So if you want to pass some integer value, you have to explicitly (or implicitly) convert it.

@Raja Pandiyan, please do not use Flag Bad Post button to post your replies as this function is for reporting posts that may be breaking forum rules in some way.
Either use Post Reply or just scroll down to bottom and you will see basic posting window where you can type your reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.