Brian Warshaw Brian Warshaw - 6 months ago 77
SQL Question

C# - SQLClient - Simplest INSERT

I'm basically trying to figure out the simplest way to perform your basic insert operation in C#.NET using the SqlClient namespace.

I'm using

for my db link, I've already had success executing some reads, and I want to know the simplest way to insert data. I'm finding what seem to be pretty verbose methods when I google.

using (var conn = new SqlConnection(yourConnectionString))
    var cmd = new SqlCommand("insert into Foo values (@bar)", conn);
    cmd.Parameters.AddWithValue("@bar", 17);