C# program that uses SqlParameter

more

/// <summary> /// Insert dog data into the SQL database table. /// </summary> /// <param name=”weight”>The weight of the dog.</param> /// <param name=”name”>The name of the dog.</param> /// <param name=”breed”>The breed of the dog.</param> static void AddDog(int weight, string name, string breed) { using (SqlConnection con = new SqlConnection( ConsoleApplication1.Properties.Settings.Default.masterConnectionString)) { con.Open(); try { using (SqlCommand command = new SqlCommand( “INSERT INTO Dogs1 VALUES(@Weight, @Name, @Breed)”, con)) { command.Parameters.Add(new SqlParameter(“Weight”, weight)); command.Parameters.Add(new SqlParameter(“Name”, name)); command.Parameters.Add(new SqlParameter(“Breed”, breed)); command.ExecuteNonQuery(); } } catch { Console.WriteLine(“Count not insert.”); } } }

techsupport
Author

techsupport