Hi @Peter_1985 , Welcome to Microsoft Q&A,
The insert statement in your screenshot is incomplete. (Do not use screenshots to submit questions.)
Before executing SQL commands, make sure that the database connection is open and that the SQL command object uses the correct connection object.
Make sure that the target table exists and that the table structure is correct, especially whether the column names, data types, etc. match the values to be inserted.
For example:
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
sqlcommand cmd7 = new sqlcommand("INSERT INTO TableName (Column1, Column2) VALUES (@Value1, @Value2)", connection);
cmd7.Parameters.AddWithValue("@Value1", value1);
cmd7.Parameters.AddWithValue("@Value2", value2);
cmd7.ExecuteNonQuery();
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.