Brian Warshaw Brian Warshaw - 1 year ago 127
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.

Answer Source
using (var conn = new SqlConnection(yourConnectionString))
    var cmd = new SqlCommand("insert into Foo values (@bar)", conn);
    cmd.Parameters.AddWithValue("@bar", 17);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download