azalikaEriya
azalikaEriya

Reputation: 195

ERROR SQL-client exception

I have query in my c# file and I have error.

            conn.Open();
            string sql = "INSERT INTO bk (a,b,c, d, guest) VALUES ('" + a+ "','" + b+ "','" + c+ "', d," + guest + " )";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
            conn.Close();

ERROR System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'juwita'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, ........

but when I delete guest on my sql. it fine.

What does it mean and what should I do ?

Upvotes: 0

Views: 347

Answers (1)

Manish Parakhiya
Manish Parakhiya

Reputation: 3798

You forgot to add single quote around 'guest' variable in your query

string sql = "INSERT INTO booking (noSeat,start,[end], statusBooked, guest) VALUES ('" + noSeat + "','" + now + "','" + bookDate + "', 1,'" + guest + "' )";

This should fix your problem.

Upvotes: 1

Related Questions