C#, DB2 & String Arrays

  • Thread starter Antoni Massó Mola
  • Start date
A

Antoni Massó Mola

Hi,

I need to connect to a DB2 database, make a select * from table where like =
'somevalue'.

Then I need to copy thos values into a string array.

Any ideas?

Thanks
 
M

Martin Dechev

Go to www.connectionstrings.com and take one of the suggested ones for DB2.
Set the parameters inside the connection string to match your database.

Then adapt some example in the OleDbConnection or OleDbRataReader classes to
your needs:
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbConnectionClassTopic.asp
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbDataReaderClassTopic.asp

At this point you should have an OleDbDataReader instance containing the
values from the select. Read these values into a
System.Collections.Specialized.StringCollection:
http://msdn.microsoft.com/library/e...ionsSpecializedStringCollectionClassTopic.asp

Then use the method CopyTo to copy the values into a string array:
http://msdn.microsoft.com/library/e...ecializedStringCollectionClassCopyToTopic.asp

Hope this helps
Martin
 
A

aqualung

Antoni -

After you make your connection, you could do the following:



Dim dt As DataTable
Dim al As New ArrayList(ds.Tables(0).Rows.Count)
dt = ds.Tables(0)
Dim i As Int32
For i = 0 To dt.Rows.Count - 1
al.Add(dt.Rows(i)(0))
Next
Dim s As String()
s = al.ToArray(GetType(String))



In this fragment ds would be your DataSet.
 

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

Similar Threads


Top