Copy contents of a returned cell/row to a text box / array

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
<em style="border:0px; font-family:inherit; margin:0px; outline:0px; padding:0px; vertical-align:baseline; background-color:transparent Tl:DR[/i] *Method of copying returned contents of an SQL query to an array or a string or a listbox. Single Columns
, multiple rows.*
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
Working on a small project for some extra course credit. Developing it currently in Visual Studio 2010. Essentially is an interactive menu where users select items and can add them to an inbuilt list and it will calculate total nutritional information and costs
etc..
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
Im having an issue however. When the user reaches the order builder page they can select the type of item they wish to buy.
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
E.G.
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
Beef
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
Clicking this should then populate a list box with all the related items.
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
Im hoping to do this via a database connection. I currently have an imbedded database.
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
Their where 2 ways Ive tried to do this but both proved unsuccessful or perhaps Im just doing it wrong.
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
First method.
<pre class="lang-sql prettyprint" style="border:0px; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; outline:0px; padding:5px; list-style-type:none; word-wrap:normal; text-align:left; overflow-y:hidden; overflow-x:auto; color:#2a2a2a; font-size:13px; vertical-align:baseline; background-color:#eeeeee; width:auto; max-height:600px; line-height:16px <code style="border:0px; font-style:inherit; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; margin:0px; outline:0px; padding:0px; font-size:13px; vertical-align:baseline <span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Dim <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px index<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px As<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Integer <span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px =<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="lit" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px 0<br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Dim length <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px As<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Integer <span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px =<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px adapter<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px .<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px productscounter<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px ()<br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="str" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Small query that works out total number of rows.<br/><br/><span class="str" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px For index = 0 To length<br/><span class="str" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px ListBox1.Items.Add(adapter.SelectBeef(index))<br/><span class="str" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px SelectBeef essentially selects <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px all<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px food items <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px with<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Beef <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px as<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px the category<br/><br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Next<br/>[/code][/code]
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
This gives me the error of There is no row at position 0. which i seem unable to solve. The query runs upon trial execution and theirs something their. Index out of range exception
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
The other method i was attempting was similar code however using an array and then copying the contents of that into the listbox.
<pre class="lang-sql prettyprint" style="border:0px; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; outline:0px; padding:5px; list-style-type:none; word-wrap:normal; text-align:left; overflow-y:hidden; overflow-x:auto; color:#2a2a2a; font-size:13px; vertical-align:baseline; background-color:#eeeeee; width:auto; max-height:600px; line-height:16px <span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Dim <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px index<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px As<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Integer<br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Dim length <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px As<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Integer <span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px =<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px adapter<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px .<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px productscounter<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px ()<br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Dim test<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px (<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px length<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px )<br/><br/><br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Dim counter <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px As<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Integer<br/><br/><br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px For<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px index<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px =<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="lit" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px 0<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px To<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px length<br/><br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px test<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px (<span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px index<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px )<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px =<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px adapter<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px .<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px SelectChicken<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px ()<br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px counter <span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px =<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px counter <span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px +<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="lit" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px 1<br/><br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Next<br/><br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px index<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px =<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="lit" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px 0<br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px For<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px counter <span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px =<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="lit" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px 1<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px <span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px To<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px length<br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px ListBox1<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px .<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Items<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px .<span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Add<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px (<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px test<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px .<span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px ToString<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px (<span class="kwd" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px index<span class="pun" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px ))<br/><br/><span class="pln" style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px Next<br/><code style="border:0px; font-style:inherit; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; margin:0px; outline:0px; padding:0px; font-size:13px; vertical-align:baseline <br/>[/code][/code]
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
Generates Argument nullexception
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
Value cannot be null. Parameter name: item.
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
Any help in this matter would be greatly appreciated,
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
Regards.
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px

<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
Note.
<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px

<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px
Also tried the following code without success.
<pre class="prettyprint lang-vb Dim index As Integer
Dim length As Integer = adapter.productCounter()
Dim test(length) As Array
Dim counter As Integer

TextBox1.Text = length
For index = 0 To length

test(index) = adapter.SelectChicken()
counter = counter + 1

Next

index = 0
For counter = 1 To length
ListBox1.Items.Add(test.ToString(index))

Next[/code]
<br/>

<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px

and...

<pre class="prettyprint Dim index As Integer = 0
Dim length As Integer = adapter.productscounter()
Small query that works out total number of rows.

For index = 1 To length
ListBox1.Items.Add(adapter.SelectChicken(index))


Next[/code]
<br/>
<br/>

<p style="border:none; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; padding-right:0px; color:#2a2a2a; text-align:left; font-size:13px; vertical-align:baseline; clear:both; word-wrap:break-word; line-height:16px


View the full article
 
Back
Top