473,503 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Convert string to Arraylist type

103 New Member
I am receiving a Cannot implicitly convert type "String" to"System.Collections.ArrayList". I new to programming so trouble shooting is an issue for me and if someone could help would be much appreciated. I highlighted the section returning the error with bold type font. Here is my code:
Expand|Select|Wrap|Line Numbers
  1. public partial class MassMailer : System.Web.UI.Page
  2. {
  3.     static string CSTR = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" +
  4.        AppDomain.CurrentDomain.BaseDirectory + "SuCasaVersion8.mdb";
  5.  
  6.     int associationID;
  7.     ArrayList massEmail;
  8.     string buildStName;
  9.  
  10.     protected void Page_Load(object sender, EventArgs e)
  11.     {
  12.         if (!IsPostBack)
  13.             populateBuildingDropDown();
  14.     }
  15.  
  16.     protected void populateBuildingDropDown()
  17.     {
  18.  
  19.         string query = "SELECT * FROM Association";
  20.         System.Data.OleDb.OleDbCommand ocmd = new System.Data.OleDb.OleDbCommand(query, new System.Data.OleDb.OleDbConnection(CSTR));
  21.         ocmd.Connection.Open();
  22.         System.Data.OleDb.OleDbDataReader dr = ocmd.ExecuteReader();
  23.         dropBuildingList.Items.Clear();
  24.         while(dr.Read())
  25.         {
  26.             string buildingName = dr.GetString(3);
  27.             string buildingID = dr.GetInt32(0).ToString();
  28.  
  29.             dropBuildingList.Items.Add(new ListItem(buildingID + ": " + buildingName, buildingID));
  30.         }
  31.         ocmd.Connection.Close();
  32.         dropBuildingList.AutoPostBack = true;
  33.     }
  34.     protected void dropBuildingList_SelectedIndexChanged(object sender, EventArgs e)
  35.     {
  36.         massEmail.Clear();
  37.         associationID = Convert.ToInt32(dropBuildingList.SelectedValue);
  38.         string query = "SELECT Email(1) FROM Occupant INNER JOIN Association INNER JOIN Association-Occupant ON"+ 
  39.         "Association.PropertyID = Association-Occupant.Property ID ON Occupant.Occupant ID = Association-Occupant.Occupant ID"+
  40.         "WHERE Association.AssociationID=@associationID GROUP BY Email(1)";
  41.  
  42.         System.Data.OleDb.OleDbCommand ocmd = new System.Data.OleDb.OleDbCommand(query, new System.Data.OleDb.OleDbConnection(CSTR));
  43.         ocmd.Parameters.AddWithValue("@associationID", associationID);
  44.         ocmd.Connection.Open();
  45.         System.Data.OleDb.OleDbDataReader dr = ocmd.ExecuteReader();
  46.         while (dr.Read())
  47.         {
  48.             massEmail = dr.GetString(8).ToString();
  49.         }
  50.         ocmd.Connection.Close();
  51.         dropBuildingList.AutoPostBack = true;
  52.  
  53.  
  54.     }
  55. }
  56.  
Mar 28 '11 #1
3 6964
GaryTexmo
1,501 Recognized Expert Top Contributor
It's exactly what the error says. massEmail is of type ArrayList and you're trying to assign a string to it.

I believe you want to use the Add method to add it to the list instead of assigning it.

http://msdn.microsoft.com/en-us/libr...=VS.71%29.aspx

The other possibility is to just make massEmail a string type instead of an ArrayList, but I don't know the details of what you're trying to do.
Mar 28 '11 #2
Brian Connelly
103 New Member
I have created a query that returns multiple email addresses. I would like to place each row into an ArrayList, but am having trouble and have spent the last two hours working on it. Can you help explain and show me how to do it? My query and code is follows:
Expand|Select|Wrap|Line Numbers
  1. massEmail=new ArrayList();
  2. associationID = Convert.ToInt16(dropBuildingList.SelectedValue);
  3.  
  4. string query = " SELECT Occupant.[Email(1)]FROM Occupant INNER JOIN"+
  5. "(Association INNER JOIN [Association-Occupant] ON Association.PropertyID "+ 
  6. "= [Association-Occupant].PropertyID) ON Occupant.OccupantID = [Association-Occupant].OccupantID"+
  7. " WHERE (((Association.AssociationID)=@associationID))GROUP BY Occupant.[Email(1)]";
  8.  
  9.         System.Data.OleDb.OleDbCommand ocmd = new System.Data.OleDb.OleDbCommand(query, new System.Data.OleDb.OleDbConnection(CSTR));
  10.         ocmd.Parameters.AddWithValue("@associationID",associationID);
  11.         ocmd.Connection.Open();
  12.         System.Data.OleDb.OleDbDataReader dr = ocmd.ExecuteReader();
  13.  
Mar 29 '11 #3
GaryTexmo
1,501 Recognized Expert Top Contributor
It looks like the result of your query is going to be a list of e-mail addresses, is that correct? I don't use these commands that often but I believe you can have a query return a data set.

At that point, you can just loop through the rows returned in the dataset and add them to the ArrayList.

Also, this seems to be roughly the same question as the other one you posted... http://bytes.com/topic/c-sharp/answe...arraylist-type. Please refrain from posting new threads on the same issue, it's generally better to keep everything in the same thread so it's easier to follow the progression of the discussion.

Thanks!
Mar 29 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
4984
by: tvn007 | last post by:
Hi, I tried to convert string data type to char type so that I can use strtok. I have used c_str(). However, still getting error message when compile . Any help would be appreciate.
2
2090
by: Mike Moore | last post by:
does anyone have an example of how to get the connection string object converted to a string variable type in order for me to call a function?
4
25328
by: John Cotsell | last post by:
Basically I have a class called Dog and when using the objectdatasource I can use a string parameter to pass into the selectmethod. so I pass in a string = 'Dog' now once in the selectmethod I need...
5
3413
by: Allerdyce.John | last post by:
Do I need to convert string to integer in python? or it will do it for me (since dynamic type)? In my python script, I have this line: x /= 10; when i run it, I get this error: TypeError:...
3
7968
by: Ursula | last post by:
Is it possible to convert a string in a file. The problem is this: I have an object string that is a file xml and I want to pass to Deserialize function, but Deserialize function expect an object...
3
9872
by: Shawn Ferguson | last post by:
Hello All, I'm trying to do what I would think would be simple and straightforward, but it is not. I have a 2 textbox on a form, a label, and a button, when I click the botton I want to add the...
7
1995
by: Saber | last post by:
In an ASP.Net Website I've a string and want to convert that to Type. Let's consider the string "Class1" I tried: Type t = Type.GetType("Class1"); but it returns null.
5
3093
by: 9966 | last post by:
Hi, currently I'm having a problem on converting a string type array into a char type. An example is as follows: string fruits; vector <char> temp; The fruits array HAS to be a string type and...
9
8225
by: engteng | last post by:
How do I convert string to numeric in VB.NET 2003 ? Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle then not convert. Regards, Tee
1
2780
by: MATTXtwo | last post by:
hi guys got in pinch here... rz.Parameters.Append rz.CreateParameter("@OldAccNo",adDecimal,adParamInput,9,OldAccNo) rz.Parameters.Append...
0
7205
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
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5592
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,...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.