In VB6, you could avoid explicit INSERT
statements by creating a recordset, inserting rows into it and calling .Update
. This could be a "direct connection" if the Command
mode was adCmdTableDirect
.
In ADO.NET, you can also do so, but there are many ways, such as Linq To Sql or Entity Framework. If you want it plain low-level vanilla VB6-like style, that'd probably be DataAdapter.Update
method.
using (System.Data.SqlClient.SqlConnection c = new System.Data.SqlClient.SqlConnection("Data Source=..."))
{
using (System.Data.SqlClient.SqlDataAdapter a = new System.Data.SqlClient.SqlDataAdapter("select * from atable;", c))
{
using (System.Data.SqlClient.SqlCommandBuilder b = new System.Data.SqlClient.SqlCommandBuilder(a))
{
using (DataTable t = new DataTable("atable"))
{
a.FillSchema(t, SchemaType.Source);
t.Rows.Add(1, "foo");
t.Rows.Add(2, "bar");
a.Update(t);
}
}
}
}