Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

Simple question: Updating a datasource

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peder Y - 21 Apr 2005 01:17 GMT
This might be a simple question, but I havent found a solution anywhere:

I do some stuff, and fill a DataSet from a database.

After the tables have been processed (rows inserted/deleted/updated) I
want to write the DataSet back to the database.

My DataTable shall replace the table in the database.

Consider the original DataAdapter disposed.

My current workaround is to create a new DataAdapter and new DataSet,
fill the new DataSet as I did from the start, replace ALL table rows
with the rows from the first table, and finally call the Update() method
to write back the changes.

This strikes me as not the proper way to do things. I don't see the
point in retrieving all rows from the database if all I want to do is
overwrite the table. Can't I create a new DataAdapter and simply tell it
to update the target table with my DataTable?

Secondly, how do I insert a single row into the target Table? Is the
proper way to write an SQL command and put it in an OleDbCommand object?

Thanks!

- Peder -
recoil@community.nospam - 21 Apr 2005 20:51 GMT
Peder,  in response to your question about "do i need to retrieve all
the rows", I believe there are at least 2 and maybe 3 ways to do it.
You should be able to build everything by hand. If you want to build it
by hand then a dataconnectionis not required to retrieve the columns
because you will add them manually via code.
If you want the columns to be added automatically you need to select at
least one row. There might be a way to read the schema from a table and
use this for a dataset. I have not seen a method of doing this so I
can't comment on whehter itis possible.

What I DO do is i do a =
bwcLogic.NewSproc("SecretOperation_PerformedOperations_ListNone"); This
is a stored procedure that basically queries the table but retrieves no
rows. Once again, this may not be the best solution, but sometimes in
the absence of more real-world practical documentation/samples we make
do with what makes sense to us.

In response to your Question about updating. This is what I do .

OleDA.InsertCommand                    =
bwcLogic.NewSproc("Dental_PerformedOperations_Insert",
    new SqlParameter("@SSN",    SqlDbType.VarChar,    50,        "SSN"),
    new SqlParameter("@Code",    SqlDbType.VarChar,    5,        "Code"),
    new SqlParameter("@Note",    SqlDbType.VarChar,    255,    "Note"),
    new SqlParameter("@Times",    SqlDbType.Int,        4,        "Times")
// Here I am using a Stored Procedure, for increased performance and
security reasons. The 4th most parameter maps the column name to the
parameter. For each row that is inserted it will execute this command
mapping as I have specified. This is why it is possible to build the
table manually with code adding the columns yourself. You just need to
make sure the data type and sizes are the appropriate data type.
// code goes here to insert all your rows
then simply go
OleDA.Update(TmpDS, TableName);
// close connections and cleanup.

Please note, that the actual order is not significant however.

Hope this helps to answer some of your questions.
Peder Y - 22 Apr 2005 17:10 GMT
Well, I fell back on writing an OleDbCommand that did the trick. I will
however use your idea of simply retrieving a single row to get hold of
the dataset upon insertion and deletion. At this point the performance
isn't an issue since the tables are small. At this point...

- Peder -

> Peder,  in response to your question about "do i need to retrieve all
> the rows", I believe there are at least 2 and maybe 3 ways to do it.
[quoted text clipped - 35 lines]
>
> Hope this helps to answer some of your questions.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.