-1

Why am i getting "incorrect syntax near @sqlFalse"?

The IsConnected column is defined as nvarchar.

Thanks.

SqlCommand cmd = new SqlCommand($"insert into clientstable (Name, NickName,isconnected) values (@sqlname,@sqlNickname ,@sqlFlase", sc);
cmd.Parameters.AddWithValue("@sqlName", textBoxName.Text);
cmd.Parameters.AddWithValue("@sqlNickname", textBox2.Text);
cmd.Parameters.AddWithValue("@sqlFalse", false);
int num = cmd.ExecuteNonQuery();
NateS
  • 33
  • 6

3 Answers3

1

change this

values (@sqlname,@sqlNickname ,@sqlFlase", sc)

to this

values (@sqlname,@sqlNickname ,@sqlFalse", sc)

as Pelle mentioned in the comments

Community
  • 1
  • 1
stathis21098
  • 31
  • 13
0

If you want to store a nvarchar but with false value the you should:

cmd.Parameters.AddWithValue("@sqlFalse", "false");

But probably you should change that type to Boolean.

Juan
  • 2,156
  • 18
  • 26
  • and consider @Pikoh comment, flag Don't edit your question to ask a new one. You are missing the closing parenthesis ... – Juan Dec 22 '16 at 15:12
0

You are probably missing a ')' after @sqlFalse

Try to copy this and see if it helps.

SqlCommand cmd = new SqlCommand($"insert into clientstable (Name, NickName,isconnected) values (@sqlname,@sqlNickname ,@sqlFlase)", sc);
Yawar Murtaza
  • 3,655
  • 5
  • 34
  • 40