Re: using "Insert Into..." with dataAdapter Insert Command?

From: Ken Tucker [MVP] (vb2ae_at_bellsouth.net)
Date: 06/15/04


Date: Tue, 15 Jun 2004 09:19:05 -0700

Hi,

        Take a look at the command builder.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlclientsqlcommandbuilderclasstopic.asp

Ken
----------

"Ed" <anonymous@discussions.microsoft.com> wrote in message
news:1cb3201c452f3$d9fb1d60$a101280a@phx.gbl:
> Hi,
>
> I want to load data to a table in Sql Server from a
> dataset table in my vb.net app using a dataAdapter. I
> know how to do this as follows (my question is to see if I
> can reduce the amount of code below):
> ...
> Dim DA As SqlDataAdapter = New SqlDataAdapter
> Dim Parm As New SqlParameter
> ...
> DA.InsertCommand = New SqlCommand("Insert Into tbl1(fld0,
> fld1, fld2) Values(@fld0, @fld1, @fld2)", conn)
> Parm = DA.InsertCommand.Parameters.Add(New SqlParameter
> ("@fld0", NVarChar, 50, "fld0"))
> Parm = sqlDA.InsertCommand.Parameters.Add(New SqlParameter
> ("@fld1", SqlDbType.NVarChar, 50, "fld1"))
> Parm = sqlDA.InsertCommand.Parameters.Add(New SqlParameter
> ("@fld2", SqlDbType.NVarChar, 50, "fld2"))
> ...
> DA.Update(dataset1, "tbl1")
> ...
>
> The parameters is where I feel I am writing too much
> code. Is there a way to say something like:
>
> DA.InsertCommand = New SqlCommand("Insert Into tbl1 Select
> * from " & dataTable.Name")
>
> Could I create a class object that is a dataTable with a
> property called "Name" or something like that? Or am I
> limited to creating a bunch of parameters for the
> dataAdapter Insert command? Or, is there a way to use the
> Sql Command object without the dataAdapter to insert All
> data to my sql server table from a dataset table (without
> looping through a dataTable object)?
>
> TIA,
> Ed
>

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.0 - Release Date: 6/12/2004


Relevant Pages

  • using "Insert Into..." with dataAdapter Insert Command?
    ... dataset table in my vb.net app using a dataAdapter. ... Dim Parm As New SqlParameter ... data to my sql server table from a dataset table (without ...
    (microsoft.public.dotnet.languages.vb)
  • Re: SQL Server Parameters
    ... DataSet so that the DataTable that I submit to my DataAdapter shows all of ... > pass this DataSet back to the SP with my DataAdapter, DumbField is passed in ... I understand what SQL Server is doing and it is doing as ... >> have a missing param or misspelled it, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Moving Data with DataSets/ADO.NET - looking for examples
    ... This gives an overview of bulk Import in sql server. ... Loading a DataSet with one dataadapter and connection. ... Pushing the DataRows back to the database as if they were new rows. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Create Update DS
    ... The Update method of the DataAdapter calls SQLServer one row at a time. ... calls SQL Server (create a DS for update, create a DS for Insert then ... I have a stored procedure which generates some values in the table. ...
    (microsoft.public.dotnet.general)
  • OpenRowSet BUG?
    ... I am trying to load data from a table in MS Access to SQL Server 2000 ... Access) using SQL Query analyzer, the columns do NOT appear in the same ... from' as the field definitions do not agree. ...
    (comp.databases.ms-sqlserver)