0

Hi guys,

I am trying to fill a datagridview on the form with data from sql server databse based on the name of the company selected in the combo box. But the code i am using gives me an error message saying "The data types text and varchar are incompatible in the equal to operator". The error is generated on line 9.
The code am using is as follows:

Dim MyConnection As SqlConnection = New SqlConnection("Initial Catalog=Returnables;" & _
                                                  "Data Source=localhost;Trusted_Connection=True;")

        Using cmd As New SqlCommand("SELECT* FROM tblReturnables WHERE Company  = @Company OR @Company = ''", MyConnection)
            Using da As New SqlDataAdapter(cmd)
                cmd.Parameters.AddWithValue("@Company", Me.cmbCompany.SelectedValue.ToString)
                Dim dt As New DataTable()
                da.Fill(dt)
                Me.dtgItemsbyCompany.DataSource = dt
            End Using
        End Using

Please help me.

2
Contributors
1
Reply
8
Views
9 Months
Discussion Span
Last Post by Shark_1
0

"SELECT* FROM tblReturnables WHERE Company = @Company OR @Company = ''"

From my opinion your problem is ni SQL Statement

It should be

"SELECT * FROM tblReturnables WHERE Company = @Company OR Company = ''"
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.