C# - SQLClient - Simplest INSERT

后端 未结 3 1892
失恋的感觉
失恋的感觉 2021-01-05 00:11

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 SqlConnection<

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-05 00:59

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

提交回复
热议问题