Home > DeveloperSection > Forums > The data types text and varchar are incompatible in the equal to operator
Jayden Bell
Jayden Bell

Total Post:110

Posted on    January-23-2014 12:04 AM

 C# C# 

 1 Reply(s)
 2614  View(s)
Rate this:

I have used text as a datatype for device name. while adding the data into the form, it throws an error : The data types text and varchar are incompatible in the equal to operator



    cmd = new SqlCommand("insert into license1 values(@l_id,@customer_id,@d_id,@device_name,@from,@to)", cn);

    cmd.Parameters.AddWithValue("@l_id", license_id.Text);

    cmd.Parameters.AddWithValue("@customer_id", c_comboBox4.Text);

    cmd.Parameters.AddWithValue("@d_id", d_id_comboBox4.Text);

    cmd.Parameters.AddWithValue("@device_name", d_name_comboBox5.Text);

    cmd.Parameters.AddWithValue("@to", DateTime.Parse(date_to.Text));

    cmd.Parameters.AddWithValue("@from", DateTime.Parse(date_from.Text));


    a = cmd.ExecuteNonQuery();

    if (a > 0)


        MessageBox.Show("Data Submitted");



catch (Exception ex)




Pravesh Singh

Total Post:412

Posted on    January-23-2014 1:04 AM

Hi Jayden,

I would try to change this line

cmd.Parameters.Add("@device_name", SqlDbType.Text).Value = d_name_comboBox5.Text;

The AddWithValue treats the string values as a NVarChar datatype and looking at error message a Text type is expected.

Don't want to miss updates? Please click the below button!

Follow MindStick