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