I want to insert a query and I want to pass the logged in User ID as a parameter, the UserID is a string.
I tried to do this:
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=project;Integrated Security=true;");
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
SqlCommand cmd = new SqlCommand("INSERT INTO Invoice VALUES (SYSDATETIME(),'@id',0)");
cmd.Connection= con;
con.Open();
cmd.Parameters.Add("@id",userId);
cmd.ExecuteNonQuery();
con.Close();
I am getting an error on cmd.Parameters.Add("@id",userId); that the userId needs to be of the data type "SqlDbType". How could I pass this var?