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.