Saving the lsitbox items state in database

  • Thread starter Thread starter Vinki
  • Start date Start date
V

Vinki

Hello Everyone,

I have a list box. I can move the items inside the listbox up and down.
Once they are done moving, I want to save the state of whatever they moved to
the database so that when I come back and see the items in the same order I
saved it before.
What will be the best way to do this. I can use a hashtable and save the
state of the items in the hashtable with the order number and save them in
the database one by one in a loop.
I was wondering if there is any other way to do this that can be faster and
effecient.

Thanks.
 
Why not just have an "Order" column in the database field and then write
the order that the items are stored in the list when you save the items to
the database? Then, when selecting the data from the database, just select
the items in order.
 
I already have a order column in the database. I am asking what will be the
best way to save those items in the database with the order.

Nicholas Paldino said:
Why not just have an "Order" column in the database field and then write
the order that the items are stored in the list when you save the items to
the database? Then, when selecting the data from the database, just select
the items in order.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vinki said:
Hello Everyone,

I have a list box. I can move the items inside the listbox up and down.
Once they are done moving, I want to save the state of whatever they moved
to
the database so that when I come back and see the items in the same order
I
saved it before.
What will be the best way to do this. I can use a hashtable and save the
state of the items in the hashtable with the order number and save them in
the database one by one in a loop.
I was wondering if there is any other way to do this that can be faster
and
effecient.

Thanks.
 
I did some research and found out that OpenXMl can be best way to insert this
data. I was wondering how cam I use OpenXML with problem.


Nicholas Paldino said:
Why not just have an "Order" column in the database field and then write
the order that the items are stored in the list when you save the items to
the database? Then, when selecting the data from the database, just select
the items in order.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vinki said:
Hello Everyone,

I have a list box. I can move the items inside the listbox up and down.
Once they are done moving, I want to save the state of whatever they moved
to
the database so that when I come back and see the items in the same order
I
saved it before.
What will be the best way to do this. I can use a hashtable and save the
state of the items in the hashtable with the order number and save them in
the database one by one in a loop.
I was wondering if there is any other way to do this that can be faster
and
effecient.

Thanks.
 
and found out that OpenXMl can be best way to insert this data
I was wondering how cam I use OpenXML

If you don't know how to do it, how do you know that it is a good
approach?
Yes, you can store complex data in xml, but you can also store it in
*tables*. Until there is a good reason (semi-structured, schema-bound,
or indeterminate structure, etc) I'd stick with tables, especially for
a simple list of alike data. Also - I probably wouldn't use OpenXML as
the implmentation; it depends on the db-server you are using, of
course... SQL Server 2005 offers a native xml datatype that doesn't
have the same issues as OpenXML re eating your memory. It also allows
you to query the data a lot more efficiently.

Of course, it really depends on what problem you are trying to solve!
(the top of the chain has disappeared from my client...)

Marc
 
Vinki,

I don't know why you think OpenXML is a good idea. That has to do with
the saving of documents in XML format. It really doesn't have anything to
do with this.

Since you have an order column, in your code, you can have a variable,
initialize it to 0 (I'm assuming your column is of type integer) and then
save the first item in the list, using the variable for the order column
value. Then, increment the value, and save the next item in the list (this
will have an order value of 1).

Do this for all the items in the list, and then when you select the data
to repopulate it later, just order by the order column.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vinki said:
I already have a order column in the database. I am asking what will be
the
best way to save those items in the database with the order.

Nicholas Paldino said:
Why not just have an "Order" column in the database field and then
write
the order that the items are stored in the list when you save the items
to
the database? Then, when selecting the data from the database, just
select
the items in order.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vinki said:
Hello Everyone,

I have a list box. I can move the items inside the listbox up and
down.
Once they are done moving, I want to save the state of whatever they
moved
to
the database so that when I come back and see the items in the same
order
I
saved it before.
What will be the best way to do this. I can use a hashtable and save
the
state of the items in the hashtable with the order number and save them
in
the database one by one in a loop.
I was wondering if there is any other way to do this that can be faster
and
effecient.

Thanks.
 
Hi Nicholas,

I have these following items in my listbox

items in listbox order

1234 1
6789 2
9876 3
9999 4




so I should insert the order in a arraylist or hashtable and call the stored
procedure like this four times

pass item as a parameter

create proc sp_test
(
@item varchar(10) -- 1234
@order int --1

)

INSERT INTO table1(order)
Values( @order)
WHERE item = @item

I just think this is an ineffecient way, If I have 40 items in my listbox, I
have to make the call 40 times to the database.

Can anyone tell me a better way.

Thanks

Nicholas Paldino said:
Vinki,

I don't know why you think OpenXML is a good idea. That has to do with
the saving of documents in XML format. It really doesn't have anything to
do with this.

Since you have an order column, in your code, you can have a variable,
initialize it to 0 (I'm assuming your column is of type integer) and then
save the first item in the list, using the variable for the order column
value. Then, increment the value, and save the next item in the list (this
will have an order value of 1).

Do this for all the items in the list, and then when you select the data
to repopulate it later, just order by the order column.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vinki said:
I already have a order column in the database. I am asking what will be
the
best way to save those items in the database with the order.

Nicholas Paldino said:
Why not just have an "Order" column in the database field and then
write
the order that the items are stored in the list when you save the items
to
the database? Then, when selecting the data from the database, just
select
the items in order.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello Everyone,

I have a list box. I can move the items inside the listbox up and
down.
Once they are done moving, I want to save the state of whatever they
moved
to
the database so that when I come back and see the items in the same
order
I
saved it before.
What will be the best way to do this. I can use a hashtable and save
the
state of the items in the hashtable with the order number and save them
in
the database one by one in a loop.
I was wondering if there is any other way to do this that can be faster
and
effecient.

Thanks.
 
If the data is that simple, then use string.Join() to create a csv:
"1234,6789,9876,9999"

Pass it down as a single varchar, and either store it as a single
varchar cell in the database, or if you want to store rows, use a UDF
at the database to parse the csv back to rows (just google "+csv +udf
+sql"). You can either tweak the UDF to include the index column, or
you could insert from the UDF into a table-variable (@table) with an
IDENTITY(1,1) column, and then INSERT/SELECT from that @table into
your actual table.

I know the above if very brief, but that is because this is a C#
forum, and everything here (except for the top line) is T-SQL ;-p
If you ask about any of the above in a SQL newsgroup then people will
be able to give full explanations.

Or stick with what you have ;-p

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top