-
February 21st, 2015, 04:06 AM
#1
SQL database, extract data in descending order to TextBox using VB.NET 4.5 OR SQL?
Hi,
I was wandering I have a SQL database which stores numbers and I can extract data from it and place it in a DataGridView. I can have it so that the numbers are placed in descending order IE 5, 4, 3, 2, 1,. I do this using SQL.
Code:
Dim dt As New DataTable("users")
sql = "SELECT * FROM Users ORDER BY UserNumber DESC"
da = New SqlDataAdapter(sql, con)
da.Fill(dt)
DataGridView1.DataSource = dt
I have just created 10 TextBoxes, 5 will hold UserNames, 5 will hold their UserNumber Now I can extract that same data and place it in TextBoxes. I do this by specifically saying which textbox the data should go in to. How would I go about rearranging that data so that it also lists the UserNumbers in order. Because when the numbers go in to my database they are in no order. So should I be using VB.NET code to rearrange the order once they are loaded in to the textBoxes? Or is their a way of using SQL to do it when fetching the data.
Code:
UserName.Text = CStr(ds.Tables("Users").Rows(0).Item(1))
UserNumber.Text = CStr(ds.Tables("Users").Rows(0).Item(2))
UserName1.Text = CStr(ds.Tables("Users").Rows(1).Item(1))
UserNumber1.Text = CStr(ds.Tables("Users").Rows(1).Item(2))
UserName2.Text = CStr(ds.Tables("Users").Rows(2).Item(1))
UserNumber2.Text = CStr(ds.Tables("Users").Rows(2).Item(2))
UserName3.Text = CStr(ds.Tables("Users").Rows(3).Item(1))
UserNumber3.Text = CStr(ds.Tables("Users").Rows(3).Item(2))
UserName4.Text = CStr(ds.Tables("Users").Rows(4).Item(1))
UserNumber4.Text = CStr(ds.Tables("Users").Rows(4).Item(2))
Thanks for reading
Nige.
-
February 24th, 2015, 08:57 PM
#2
Re: SQL database, extract data in descending order to TextBox using VB.NET 4.5 OR SQ
Use the datatable with the order by clause like in the first piece of code and then step through the data
Always use [code][/code] tags when posting code.
-
March 7th, 2015, 03:59 AM
#3
Re: SQL database, extract data in descending order to TextBox using VB.NET 4.5 OR SQ
can have it so that the numbers are placed in descending order IE 5, 4, 3, 2, 1,. I do this using SQL.
_______________
Arslan1
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|