I have a simple select query but executing it gives me an error:
Datatypes text and varchar incompatible in the equal to operator
Here is the code:
string query = String.Format("Select SupplierId from tbl_Supplier where SupplierName ='" + cmbSupplierName.Text +"'");
SqlCommand cmd = new SqlCommand(query, connection);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
MessageBox.Show(sdr["SupplierId"].ToString());
}
The datatype for SupplierName is TEXT in the database. I am not getting why it gives me error for varchar
If SupplierName is really a text field, try:
Text is an old and deprecated column type. Back in the days, it could contain more than 8000 characters, more than
varchar. Since SQL Server 2005 that role is better filled byvarchar(max).It would be an amazing supplier that has a name with more than 8000 characters though.