473,567 Members | 3,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# listview and database update question

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

Dec 17 '05 #1
1 2323
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.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethi s.dystopia.fi
http://www.saunalahti.fi/janij/
Dec 18 '05 #2

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

Similar topics

1
787
by: J_Max | last post by:
Hello, This might be a really easy question, but... I am developing a simple Smart Device application that uses a listview. I have a function that adds a item to the listview - code is below. I use the type listviewitem, selitem, on one form to modify the listviewitem, using a timer, every second, and use selitem1 to modify items, after...
7
6426
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override ListView.Items.Add(), . I see that it is a virtual method so it should be easy to do. If anyone can help I would appreciate it greatly. I can do what...
0
1413
by: Sérgio Almeida | last post by:
Greetings I have a problem using listview control. Well, I belive that this is not realy a problem, but it's consuming me precious time. Here is the scenario (an example of my problem). I have a SqlServer CE table named students that has 2 fields: students name and grade.
3
9293
by: MikeY | last post by:
Hopefully someone can help me on this. I am using C#, making Windows forms. I have created a listView with checkbox's. I have enabled the checkboxes under the properties, and all the data, checkbox's and icons are displayed as they are meant to be. My problem is this, I am trying to achieve the same results as I get with CheckListBox(s),...
0
5405
by: PeacError | last post by:
Using Microsoft Visual Studio .NET 2003, Visual C# .NET 1.1: I apologize if this question has been addressed elsewhere, but I could not find a reference to it in the search engine for this board. I have a form that contains a ListView and a GroupBox control. The GroupBox control itself contains several TextBox Controls. I have...
1
346
by: Kenneth | last post by:
I have a listview that fill up some texboxes on a form when I select a listviewItem when I scrolldown in the listview the textbox is update for each item I set focus to. Now to the help I need If we say that for each item my program fetch data from a database, and if I scroll down 20 items it should be 20 questions to the database,...
1
2851
by: Chris | last post by:
Hi all, I posted the following in microsoft.public.dotnet.framework.windowsforms but it seems that group has little traffic. Hi all, I have a listview box which is populated from methods of objects stored in a List<T> collection. The items in this collection are generated from a user filled out form. The items in the listview have the...
10
4028
by: Rob | last post by:
VS 2005 How can you tell if a value is contained in a specific column (let's say column 1 named Status) of a ListView ? In a list box you could go... If ListBox1.Items.Contains(strWhatever) then How would you accomplish this using a ListView ?
1
2166
by: =?Utf-8?B?THluYkBtcy5jb20=?= | last post by:
I have a executable winforms application I would like to change. I use quite a number of listview controls in my main form. I dump about 15 columns of data into a couple of listviews. This data comes from classes that implement Ienumerable ... I use a method in the main form to update the listviews... s. I want to change this application...
0
7688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7590
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8115
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7651
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6272
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5216
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3630
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
930
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.