Remove the quotation marks and use the AddWithValuemethod as follows:
SqlCommand cmd = new SqlCommand("insert into TestTable values(@Firstname,@Lastname)", con);
cmd.Parameters.AddWithValue("@Firstname",firstname);
cmd.Parameters.AddWithValue("@Lastname",lastname);
Your actual problem is quotation marks. When using quotation marks, @Firstnameand are @Lastnametreated as actual values instead of parameters. You do not need to use the method AddWithValue, but it is shorter and easier to use. You do not need to create SqlParameterfor each parameter and set each property each time.
source
share