Avatar of bkrenzin
bkrenzin

asked on 

How do I load data from sql into an unbound DataGridView

I would like to load data from a sql table into an unbound dgv to allow for us to reorder the rows using up & down buttons then use a save button to write back to sql the values of a hidden sort order column for each of the rows.

Can someone provide me with some guidance on where to start?
.NET ProgrammingC#

Avatar of undefined
Last Comment
mortimer452
ASKER CERTIFIED SOLUTION
Avatar of J K
J K
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of bkrenzin
bkrenzin

ASKER

I  read through that document several days ago and it appears to me that it describes creating a bound dgv.

It is my understanding that I need to create an unbound dgv to allow for the rows to be moved up and down.

Am I correct in that understanding?
Avatar of mortimer452
mortimer452

I assume the source of your data is an SQL table?

The only way to re-arrange the order of rows in a table is to change the value of some column in the table.  For example, if your table had an integer column named Sort_Order, you could change the value of this column to re-order the rows.
Avatar of bkrenzin
bkrenzin

ASKER

The data is in a sql table.  Since the table is a default table of our accounting software....  I would take the approach of creating an additional table and creating a relationship between them.

If you could could you please point me in a direction that possibly allows me to rearrange the sort order in the following example:

The data would come from 2 tables.  RM00100 and gsi_route_sort_order

The query would look something like this:

Select a.CUSTNUM, a.SHIPMTHD, c.SORTORDER from RM00101 a 
OUTER APPLY
   (
   SELECT CUSTNUM, SHIPMTHD, SORTORDER FROM gsi_route_sort_order b
   WHERE b.CUSTNUM = a.CUSTNUM and b.SHIPMTHD = a.SHIPMTHD
   ) c 

Open in new window

Avatar of mortimer452
mortimer452

The below should work, based on the following assumptions:

- RM00101 primary keys are CUSTNUM and SHIPMTHD.  If not, more than one entry in gsi_route_sort_order could match entries in RM00101
- This uses an INNER JOIN, so every record in RM00101 must have a matching entry in gsi_route_sort_order.  If not, this query will only return records that do have a matching entry.

SELECT rm.custnum, rm.shipmthd, grso.sortorder
FROM rm00101 rm
INNER JOIN gsi_route_sort_order grso ON 
     gsro.custnum = rm.custnum AND
     gsro.shipmthd = rm.shipmthd
ORDER BY gsro.sortorder

Open in new window

.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo