473,396 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

2D array of string

Sam
Hi,
I'm not very good at using arrays in vb. I would like to do the
following :

'browse my dataset's records
For Each dr As DataRow In dsFields.Tables(1).Rows

' add (dr("column_name").ToString to an array of strings[][]
' add (dr("data_type").ToString to the same array of strings[][]
Next

so it should be a 2D array : myArray[column_name][data_type]

How can I do that ?
thx

Nov 21 '05 #1
8 2828
Sam wrote:
'browse my dataset's records
For Each dr As DataRow In dsFields.Tables(1).Rows
' add (dr("column_name").ToString to an array of strings[][]
' add (dr("data_type").ToString to the same array of strings[][]
Next

so it should be a 2D array : myArray[column_name][data_type]


Is this kind of thing what you want:
Dim theArray(dsFields.Tables(1).Rows.Count, 2) As String
Dim rowIndex As Integer

For Each dr As DataRow In dsFields.Tables(1).Rows
theArray(rowIndex, 0) = dr("column_name").ToString
theArray(rowIndex, 1) = dr("data_type").ToString
rowIndex += 1
Next

Then you can access the column names as theArray(rowNum,0) and the datatypes
as theArray(rowNum,1).

--

(O) e n o n e
Nov 21 '05 #2
Sam
thanks it worked. However i can't figure out how to browse through the
records ? Could you give me a loop example ?
thx

Nov 21 '05 #3
Sam,

I certainly would not do that in your combobox chalenge.
When you use something as my sample than you can better create a new table.
That is much easier to set as datatasource and than to use the displaymember
and the value.

Roughly typed in this message

\\\
dim dtnew as new datatable
dim dtnew.column.add("1")
dim dtnew.column.add("2")
for each dr as datarow in my olddatatable.rows
dt.LoadDataRow(New Object() {dr("old1").ToString, dr("old2")ToString}, True)
next
////

I hope this helps,

Cor
Nov 21 '05 #4
Sam wrote:
thanks it worked. However i can't figure out how to browse through the
records ? Could you give me a loop example ?


You mean how to loop through the array and retrieve the data?

Try this:

Dim i As Integer

For i = 0 To UBound(theArray,1)
Debug.WriteLine("Line " & i)
Debug.WriteLine("Column Name = " & theArray(i,0))
Debug.WriteLine("Data Type = " & theArray(i,1))
Next

The UBound function is given a second parameter (the value 1) to indicate
that it should return the number of elements in the first dimension (which
will match the number of rows that were added), rather than the second
dimension (which will always be 2 as there are two columns stored, one for
the Column Name and one for the Data Type).

--

(O) e n o n e
Nov 21 '05 #5
Sam
Oenone,
Thanks. I had done it like this:
For i = 0 To mylist.GetLength(0) - 1
Dim dt() As DataRow = myDatatable.Select("Country = '" &
mylist(i, 0).ToString & "'")
Next
I guess it's the same...

Cor,
I'm not sure what you mean ? Could you explain again if you don't mind
? It is indeed for my combobox challenge ;)

Nov 21 '05 #6
Sam,

I have created a datatable instead of an arraylist.
(The code is completly different from Oenone by the way)

The datatable fits direct on your combobox with a datasource.

The arraylist gives me mostly only one thing when used for that "Trouble".

(I never use that for that forever anymore in Net 1.1).

Cor
Nov 21 '05 #7
Sam
but then in your code of this morning, when you passed a String to
DataGridComboBoxColumn, I should pass a datatable now ?
How can I check an item is selected in another combobox ? I've done it
like this with the array:

For i = 0 To mylist.GetLength(0) - 1
Dim dt() As DataRow = myDatatable.Select("column_name = '"
& mylist(i, 0).ToString & "'")
If dt.Length = 0 Then
ColumnComboBox.Items.Add(mylist(i, 0).ToString)
End If
Next

How can I do it with a datatable ?
thx

Nov 21 '05 #8
Sam,

You said that you said that you did want to use the display and the
valuemember, I typed it in this message so watch typos

However the same with a datatable would be something as absolutly not tested
because you would first have to find how you use can use that display and
value member..

\\\\
dim dtSource as new datatable
dim dtnew.column.add("1")
dim dtnew.column.add("2")
For Each dr As datarow in myCountryTable
Dim drc() As DataRow = myDatatable.Select("Country = '" & dr("Country") &
"'")
If dt.Length = 0 Then
dtSource.LoadDataRow(New Object()
{dr("Country").ToString,dr("CountryValue").ToStrin g}, True)
End If
next
Dim dre() As DataRow = myCountryTable.Select("Country = '" & me.Textbox.Text
& "'")
dtSource.LoadDataRow(New Object()
{dre("Country").ToString,dre("CountryValue").ToStr ing}, True)
///

I hope this helps anyhow

Cor


Nov 21 '05 #9

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

Similar topics

2
by: Techie Guy | last post by:
I'm trying to process a tab delimited file where each line in the file has around 12 tab delimited elements. My problem is the elements are surrounded by "quotes" and I need the script to remove...
3
by: Sam Clark | last post by:
The following code puts a structure location in an array field: XrefArray(i) = "ArrayIn(i).Field" & RefText.Substring(NumStart + 1) --------------------------------------------------------...
1
by: Sam Clark | last post by:
The following code puts a structure location in an array field: XrefArray(i) = "ArrayIn(i).Field" & RefText.Substring(NumStart + 1) --------------------------------------------------------...
3
by: marfi95 | last post by:
Hi all. I need to copy a byte array into a string, but starting at a specific location in the byte array. This is where I get hung up. For example if my byte array is (100) big, I might want to...
14
by: Peter Hallett | last post by:
I would like to set up a string array as a class member, or field, and then populate this array by reading in from a text file, but I cannot find the appropriate syntax. The getter and setter are...
1
by: spud379 | last post by:
i am doing an assignment in vb.net. i have to select at random from and array what i have is dim country(29) as string dim random as new random txtcountry.text = random.next(country) I...
4
by: =?Utf-8?B?aXdkdTE1?= | last post by:
hi, im having a small issue. I pass a String object to a method, but then when i try to use the Split method of a String array, it says System.Array does not contain Split. The parameter of my...
4
by: Mokita | last post by:
Hello, I am working with Taverna to build a workflow. Taverna has a beanshell where I can program in java. I am having some problems in writing a script, where I want to eliminate the duplicates...
1
by: Piero | last post by:
Hi, i must create an string array to save a record of a txt file.... the number of record is't the same... someone can help me? thanks
1
by: anup joshi | last post by:
HI TO ALL....... This Problem Is Occour To Me When Passing Pointer Array To The Function....... So plse Give Me Answer.........
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.