473,387 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

Ed
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
Nov 20 '05 #1
3 37788
Hi,

Take a look at the command builder.
http://msdn.microsoft.com/library/de...classtopic.asp

Ken
----------

"Ed" <an*******@discussions.microsoft.com> wrote in message
news:1c*****************************@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
Nov 20 '05 #2
Ed
Many thanks for your help! I could never figure out how
to use the commandbuilder - you have to use the
dataAdapter as an argument. Now I get it! Works great!

Many thanks,
Ed

-----Original Message-----
Hi,

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

"Ed" <an*******@discussions.microsoft.com> wrote in messagenews:1c*****************************@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

.

Nov 20 '05 #3
* "Ed" <an*******@discussions.microsoft.com> scripsit:
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


Just FYI: There is a separate group for .NET + database (ADO.NET)
related questions avaliable:

<URL:news://news.microsoft.com/microsoft.public.dotnet.framework.adonet>

Web interface:

<URL:http://msdn.microsoft.com/newsgroups/?dg=microsoft.public.dotnet.framework.adonet>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mukesh Kumar | last post by:
hi all, I have created some independent reports through crystal reports developer edition v 10 and developed a small tool in .net framework v 1.1 to view these reports through the crystal reports...
1
by: bjbounce2002 | last post by:
Hello, I am using forms with command buttons to close form or run action queries. The error messages such as "Null value in required field" or "duplicate value in primary key" are suppressed....
10
by: eyh5 | last post by:
Hi, My C code (running on Soalris Unix) has some "segmentation fault" that I wish to use purify to do it. I poked around the web, and found some information about adding some lines in a Makefile...
5
abdoelmasry
by: abdoelmasry | last post by:
Hey could any one tell me is there away to end any proccess using command line ?? i can get all running proccesses using command (tasklist) ThX
1
by: sandeep.damodar | last post by:
Hello, I need help.. I am just trying to insert data from the datagrid to data source, using insert sql statement.
2
by: mdfayazi | last post by:
I am using dataadapter to Add,Update,Delete rows in a datagridview.Update and delete are working but while adding a rows the problem comes.When I add more than one row only first row values are...
2
by: pattie | last post by:
I hava been trying to add data into a table using INSERT into unsuccessfully.Doing it manually works,and all other constructs works like SELECT,UPDATE.So what might be a cause. My syntax ...
7
by: jthep | last post by:
Hi, I'm a newbie at this but how can I populate a table with data from other tables by using INSERT statements? Below is of what I have so far, I have to populate the PERSON_PROFILE table. I've...
1
by: 85ssp | last post by:
I am working on debugging a multithreaded network application. I have two forms. One of which is my testing form, the other is the actual user form. I need to be able to load only my testing form...
3
by: Israel | last post by:
I always wondered why the using command can only take one object. I always find that this isn't sufficient for drawing so I end up always disposing in my finally block but then I have to remember...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.