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 / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

C# listview and database update question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason Huang - 17 Dec 2005 03:33 GMT
Hi,

In my C# Windows Form MyForm, there's one ListView control listView1 in the
MyForm.
The ListViewItem in the listView1 MATCHING EXACTLY the data in a SQL Server
database table Customer.
e.g.,
Serial    ID    Name
----------------------------
1        123    John
2        125    Marry
3        201    Leo
4        305    Britney

If we DELETE the first Row [1,123, John] in the listView1, we will reasign
the Serial for the rest Rows.
the result:
Serial    ID    Name
----------------------------
1        125    Marry
2        201    Leo
3        305    Britney

Then we DELETE everything form the database table Customer.
Later on we INSERT back [1,125,Marry],[2,201,Leo],[3,305,Britney] to
database Customer.

I have a feeling that something Very Wrong with that process, but I don't
know what's the solution.
Would someone give us some advice?
Thanks for help.

Jason
Jani Järvinen [MVP] - 18 Dec 2005 10:10 GMT
Hello!

> If we DELETE the first Row [1,123, John] in the listView1, we will reasign
> the Serial for the rest Rows.
>
> Then we DELETE everything form the database table Customer.
> Later on we INSERT back [1,125,Marry],[2,201,Leo],[3,305,Britney] to
> database Customer.

Uh oh Jason, if I understood you correctly, then your gut feeling is
correct: you shouldn't be doing things this way. Okay, your solution does
work, but imagine what would happen if you would have something like 1000
customers (or 1,000,000) instead of just three? A performance nightmare to
say the least!

It is often a requirement in applications to have some kind of counter that
runs from 1 to the number of items (customers in this case). However, unless
you have special requirements for example about sorting/item ordering, it is
often enough to only display those numbers on the client, but never store
them on the database.

That is, now your database has the Serial, ID and Name fields. What would
happen if you wouldn't store the Serial in the database at all? If you
choose this route, you could use the ID field (I'm assuming it is unique
among all customer records) as a key to delete data from the database, and
then you would simple recreate all Serials on the client's ListView. This
should be very fast.

So, the Serial number would only be a virtual value that you generate
on-the-fly in the code. With this solution, you would never need to delete
all customers from the database and then recreate them, since the database
wouldn't have the Serial field at all. You could however still sort by Name
and ID, which might be enough for you.

Does this make sense to you? Of course, this is a simplistic solution, but
without knowing more about your specific needs, it if difficult to suggest a
definite solution.

Signature

Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
janij@removethis.dystopia.fi
http://www.saunalahti.fi/janij/


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.