RE: how to insert record in a dataSet into another database table

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Toyin,

Here is an example of inserting a new row into a table where the data for
the new row comes from a row in a datatable in a dataset:

Private Sub InsertRow(ByVal ds As DataSet)

Dim cn As New SqlConnection("Data Source=(local)\SQLExpress;Initial
Catalog=CollegeRecords;User ID=sa;Password=xxxxxxx")

Dim cmd As New SqlCommand

cmd.CommandText = "Insert Into Courses (CourseID, Title, Period,
Room) Values (@CourseID, @Title, @Period, @Room)"

cmd.Parameters.AddWithValue("@CourseID",
ds.Tables(0).Rows(0)("CourseID"))
cmd.Parameters.AddWithValue("@Title", ds.Tables(0).Rows(0)("Title"))
cmd.Parameters.AddWithValue("@Period", ds.Tables(0).Rows(0)("Period"))
cmd.Parameters.AddWithValue("@Room", ds.Tables(0).Rows(0)("Room"))

cn.Open()

cmd.Connection = cn

cmd.ExecuteNonQuery()

cn.Close()

MsgBox("Inserted")

End Sub

Kerry Moorman


"Toyin" wrote:

hello Kerry,
thx for your response. but i need the code for the inser statement. is this
correct
dim comm AS New OdbcCommand("Insert Into table2 Select * from" + oDS.Tables(0)
with the above code i still get an error that operator + is not defined for
string and system.data.dataTable.

pls send the insert statement to me.

thx
Toyin

"Kerry Moorman" wrote:
Toyin,

Once you have the record in a datatable within a dataset:

Open a connection to database y
Use a command object to execute an SQL Insert statement
Insert a new row into table y in database y, using the data from the record
in the datatable within the dataset

Kerry Moorman


"Toyin" wrote:

hello,
thx for ur reply but it still can solve my problem.i have a record already
in a dataset (ds) i want to push the record in this ds into another table
(y) in database(y) without making any changes to it .
thx

"JIGNESH" wrote:

Your questiona bit confused me, but based on my understanding, you have
retrieved data into dataset from X database and now want to save the same in
Y database.

This is possible if you have right dataAdaptors for each database(X & Y)
eg.
dataAdaptor1 = new ("Select col1 , col2 from TableXDatabase1")
dataAdaptor2 = new ("Select col1 , col2 from TableYDatabase2")

dataAdaptor1.Fill(ds)
// Make Necessary Changes and
dataAdaptor2.Update(ds)

Regards
JIGNESH

"Toyin" wrote:

hi, pls can someone help me out. its very urgent i get the solution today. i
have a webservice that i use to retrieve new record from a database, also
there is a client application (window form) that calls this service which
returns the record in a dataset. now i need to insert the record in this
dataset into another database table on a different server.how do i do these.i
've tried so many things and also implement a suggestion on a thread about
inserting from one db into another but its not working. am using MySql5.1
community edition,IIS 5.o and Visual studio.Net2003 to develop and test. pls
someone help me. i need a simple code to do this.
.



Relevant Pages

  • Re: Requery "Too Soon"?
    ... "The database has been placed in a state by user ... then the Requery will return the just ... MsgBox appears, I get an empty subform, i.e., I do ... I'll try inserting a DoEvents or two. ...
    (microsoft.public.access.formscoding)
  • Re: SQLCE performance from .NET CF v2.0
    ... Please remember when bulk inserting is being executed against SQL CE, ... > local database functionality. ... > database technology and I am considering switching to SQLCE at the same ... > execute the prepared statement again. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Formatting an inserted database field
    ... stop inserting unnecessary and unwanted Carriage Returns. ... DATABASE fields at some point which does cause an unhelpful extra ... When viewing the document without Show/Hide formatting selected (and ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Transforming ascii file (pseduo database) into proper database
    ... contained therein so that it can be inserted into an existing database. ... So I iterate over the file maintaining a list of calls for the given phonenumber, and when the phonenumber changes, I deal with the previous cache of data, then re-initialize with the new phone's data. ... create a temp DB, skim through the file inserting all your data into a table in this DB, then use DB functionality on it ...
    (comp.lang.python)
  • perl with mysql which takes a file as a input that contains t he info to create the tables
    ... inserting values into the database. ... only procedure for taking input from a file (using perl script) into ... MySQL database is through place holders. ... Where the passlist.txt hav the data in the format ...
    (perl.beginners)