1

Is it somehow possible to move a 2 dimensional array directly into a database (SQL Server) without transforming it into a SQL statement?

I know there was some kind of direct connection in vb6.0, but I can not remember how it was done then, nor if it is still possible.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ralph
  • 93
  • 2
  • 8
  • possible duplicate of [How to pass User Defined Table Type as Stored Procedured parameter in C#](http://stackoverflow.com/questions/1030848/how-to-pass-user-defined-table-type-as-stored-procedured-parameter-in-c) – GSerg Jun 30 '11 at 21:48
  • i will look into it. but it is not quite what i was thinking about. – ralph Jun 30 '11 at 21:57
  • Well, that's what you get when your question can be comprehended in more than one way :) – GSerg Jun 30 '11 at 22:08

1 Answers1

0

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);

            }
        }
    }
}
GSerg
  • 76,472
  • 17
  • 159
  • 346