I am receiving a Cannot implicitly convert type "String" to"System.Colle ctions.ArrayLis t". 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: - public partial class MassMailer : System.Web.UI.Page
-
{
-
static string CSTR = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" +
-
AppDomain.CurrentDomain.BaseDirectory + "SuCasaVersion8.mdb";
-
-
int associationID;
-
ArrayList massEmail;
-
string buildStName;
-
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
if (!IsPostBack)
-
populateBuildingDropDown();
-
}
-
-
protected void populateBuildingDropDown()
-
{
-
-
string query = "SELECT * FROM Association";
-
System.Data.OleDb.OleDbCommand ocmd = new System.Data.OleDb.OleDbCommand(query, new System.Data.OleDb.OleDbConnection(CSTR));
-
ocmd.Connection.Open();
-
System.Data.OleDb.OleDbDataReader dr = ocmd.ExecuteReader();
-
dropBuildingList.Items.Clear();
-
while(dr.Read())
-
{
-
string buildingName = dr.GetString(3);
-
string buildingID = dr.GetInt32(0).ToString();
-
-
dropBuildingList.Items.Add(new ListItem(buildingID + ": " + buildingName, buildingID));
-
}
-
ocmd.Connection.Close();
-
dropBuildingList.AutoPostBack = true;
-
}
-
protected void dropBuildingList_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
massEmail.Clear();
-
associationID = Convert.ToInt32(dropBuildingList.SelectedValue);
-
string query = "SELECT Email(1) FROM Occupant INNER JOIN Association INNER JOIN Association-Occupant ON"+
-
"Association.PropertyID = Association-Occupant.Property ID ON Occupant.Occupant ID = Association-Occupant.Occupant ID"+
-
"WHERE Association.AssociationID=@associationID GROUP BY Email(1)";
-
-
System.Data.OleDb.OleDbCommand ocmd = new System.Data.OleDb.OleDbCommand(query, new System.Data.OleDb.OleDbConnection(CSTR));
-
ocmd.Parameters.AddWithValue("@associationID", associationID);
-
ocmd.Connection.Open();
-
System.Data.OleDb.OleDbDataReader dr = ocmd.ExecuteReader();
-
while (dr.Read())
-
{
-
massEmail = dr.GetString(8).ToString();
-
}
-
ocmd.Connection.Close();
-
dropBuildingList.AutoPostBack = true;
-
-
-
}
-
}
-
3 6994 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.
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: -
massEmail=new ArrayList();
-
associationID = Convert.ToInt16(dropBuildingList.SelectedValue);
-
-
string query = " SELECT Occupant.[Email(1)]FROM Occupant INNER JOIN"+
-
"(Association INNER JOIN [Association-Occupant] ON Association.PropertyID "+
-
"= [Association-Occupant].PropertyID) ON Occupant.OccupantID = [Association-Occupant].OccupantID"+
-
" WHERE (((Association.AssociationID)=@associationID))GROUP BY Occupant.[Email(1)]";
-
-
System.Data.OleDb.OleDbCommand ocmd = new System.Data.OleDb.OleDbCommand(query, new System.Data.OleDb.OleDbConnection(CSTR));
-
ocmd.Parameters.AddWithValue("@associationID",associationID);
-
ocmd.Connection.Open();
-
System.Data.OleDb.OleDbDataReader dr = ocmd.ExecuteReader();
-
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!
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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?
|
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 to convert that string
into and object of type Dog...I hope this makes sense. Do anyone know how to
do this???? i guess I need a similar method to Eval in javascript.
Please need urgent so could replies also go to johncotsell@hotmail.com
...
|
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: unsupported operand type(s) for /=: 'unicode' and 'int'
I want to divide x by 10 and assign that value back to x.
|
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 of FileStream type and
the mode access.
There is a function Convert.ChangeType(object value, Type conversionType),
but I cant write for example:
Convert.ChangeType(mystring, FileStream);
CAN YOU HELP ME????? thanks
| |
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 2 textboxes and place the value in the label. Unfortunately, when I try to convert.Int32(txtBox1.Text) I get cannot convert string to int error. Basically, Im doing this:
int x;
int y;
x = (int) Convert.ToInt32(TextBox1.Text);
y = (int)...
|
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.
|
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 temp vector HAS to be a char type. This can't be changed. So I've a problem on storing the element of fruits array into temp vector as follows:
temp.push_back(fruits); <-----I know this is wrong.
So can I know how to convert string array into...
|
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
|
by: MATTXtwo |
last post by:
hi guys got in pinch here...
rz.Parameters.Append rz.CreateParameter("@OldAccNo",adDecimal,adParamInput,9,OldAccNo)
rz.Parameters.Append rz.CreateParameter("@NewAccNo",adChar,adParamInput,11,NewAccNo)
rz.Parameters.Append rz.CreateParameter("@RewardNo",adVarChar,adParamInput,15,RewardNo)
rz.Parameters.Append rz.CreateParameter("@NewICNo",adChar,adParamInput,12,NewICNo)
rz.Parameters.Append...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |