GlobaLevel
asked on
C#.net - errors in code....
I have this code and there are several errors including the arraylist....
the code basically pulls items from a database and binds to a dropdown list
the code basically pulls items from a database and binds to a dropdown list
if (flag == "Array")
{
try
{
DropDownList MyDropDown = default(DropDownList);
string TC_ID = null;
ArrayList myArray = new ArrayList();
SqlDataReader dataReader = default(SqlDataReader);
int x = 0;
string sqlConnection = null;
TC_ID = Session["SessionTC_ID"];
MyDropDown = DropDownList1;
using (SqlConnection sqlConn = new SqlConnection())
{
sqlConnection = "Data Source=xx.xx.xx.xx;Initial Catalog=sddasdas;Trusted_connection=true;";
sqlConn.ConnectionString = sqlConnection;
string SQLstring = "SELECT distinct(campaign_name) FROM campaign WHERE TC_ID = '" + TC_ID + "'";
sqlConn.Open();
using (SqlCommand command = new SqlCommand(SQLstring, sqlConn))
{
dataReader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
if (dataReader.HasRows)
{
while (dataReader.Read())
{
myArray.Add(dataReader("camp_name").ToString());
}
}
dataReader.Close();
sqlConn.Close();
}
}
myArray.Sort();
MyDropDown.DataSource = myArray;
MyDropDown.DataBind();
}
catch (Exception ex)
{
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
while (dataReader.Read())
{
myArray.Add(dataReader("ca
}
>>>datareader is a variable being used as a method
==========================
TC_ID = Session["SessionTC_ID"];
>>>>casting error?
CANNOT IMPLICITLY CAST 'OBJECT' TO 'STRING'