I am trying to insert data into a database, but I keep getting this error on this line of code:


This is the error I get:

The data types text and text are incompatible in the equal to operator.

Here is my method:

public List<QuestionsClass> updateQuestions(List<QuestionsClass> items)
            connection = new SqlConnection(connectionString);
            command = new SqlCommand(@"IF EXISTS(SELECT * FROM QuestionnaireAnswer WHERE questionID = @questionID AND community = @community AND lot = @lot)
                                            UPDATE QuestionnaireAnswer SET answer = @answer, textBox = @textBox WHERE questionID = @questionID AND community = @community AND lot = @lot
                                            INSERT INTO QuestionnaireAnswer (questionID, answer, community, lot, textBox) VALUES (@questionID, @answer, @community, @lot, @textBox)

            command.Parameters.Add("@questionID", System.Data.SqlDbType.Int);
            command.Parameters.Add("@answer", System.Data.SqlDbType.Text);
            command.Parameters.Add("@community", System.Data.SqlDbType.Text);
            command.Parameters.Add("@lot", System.Data.SqlDbType.Int);
            command.Parameters.Add("@textBox", System.Data.SqlDbType.Text);

            command.Connection = connection;

            for (int i = 0; i < items.Count; i++)
                command.Parameters["@questionID"].Value = items[i].questionID;
                command.Parameters["@answer"].Value = items[i].answer;
                command.Parameters["@community"].Value = items[i].community;
                command.Parameters["@lot"].Value = items[i].lot;
                command.Parameters["@textBox"].Value = items[i].textBox;


            return items;


Here is my QuestionsClass

public class QuestionsClass
        public int questionID { get; set; }
        public string answer { get; set; }
        public string community { get; set; }
        public int lot { get; set; }
        public string textBox { get; set; }

answer, community and textBox are being populated with strings.

In my Database answer, community and textBox are Data types Text. What Am I doing wrong?

Please Help.

Related posts

Recent Viewed