Question How to find INTEGER type column on a datagrid?

black zero

Well-known member
Joined
Jan 15, 2009
Messages
53
Programming Experience
Beginner
Might be a little bit hard to explain,

I have this code run on form load event:

VB.NET:
Try
            Module1.OpenCon2()
            da = New SqlDataAdapter("select * from kelancaran", Module1.xcon)
            da.Fill(ds, "edit")
            da.Dispose()

            For i As Integer = 0 To ds.Tables("edit").Columns.Count - 1
                cbospr.Items.Add(ds.Tables("edit").Columns(i).ToString)
            Next
            cbospr.SelectedIndex = 0

            dv = ds.Tables("edit").DefaultView
            DgCrTransaksi.DataSource = dv
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

That will load all records inside kelancaran table into a dgcrtransaksi AND column titles on cbospr. This is so far, working fine.

And there's a second code like this:

Try
If txtFilter.Text <> "" Then
dv.RowFilter = cbospr.SelectedItem & " like '%" & txtFilter.Text & "%'"
Else
dv.RowFilter = ""
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try

I put the second code on a textbox_change event (please see image below).

However, that code isn't working for all data types. If the column is integer, it would produce this error 'Cannot perform 'Like' operation on System.Int32 and System.String.'. But, it does work fine on VarChar type column.

FYI, here's my form screenshot:

kelancaranedit.JPG

=.= Sorry, I am stuck here... Help, please?
 
No no no, I checked my database and I am sure there's only one transaction with id '1'.

I forgot to tell you all:

Private Sub loadcaridg()
Try
Module1.OpenCon2()
da = New SqlDataAdapter("select * from kelancaran", Module1.xcon)
da.Fill(ds, "edit")
da.Dispose()

For i As Integer = 0 To ds.Tables("edit").Columns.Count - 1
cbospr.Items.Add(ds.Tables("edit").Columns(i).ToString)
Next
cbospr.SelectedIndex = 0

dv = ds.Tables("edit").DefaultView
DgTransaction.DataSource = dv
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

I have this code, and is loaded on form load event. So this code loads all transaction and bind it to datagrid. However, I also use bindingsource to bind the table to the very same datagrid. I use the binding to retrieve the transaction id based from datestart and dateend (see screenshot above, retrieve code below). These codes below were from jmcilhinney.

Private Sub timestart_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timestart.ValueChanged
KelancaranEditBindingSource.Filter = String.Format("transaction_date >= #{0:M/dd/yyyy}# AND transaction_date <= #{1:M/dd/yyyy}#", Me.timestart.Value, Me.timeend.Value)
End Sub

Private Sub timeend_ValueChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timeend.ValueChanged
KelancaranEditBindingSource.Filter = String.Format("transaction_date >= #{0:M/dd/yyyy}# AND transaction_date <= #{1:M/dd/yyyy}#", Me.timestart.Value, Me.timeend.Value)
End Sub

In short, two data sources that bind themselves to the same grid. Is that the problem?
 
Back
Top