c#.net - errors with code

I have an error with this line:

DataSet Tbl = new DataSet();

also
   TC_ID == Session["SessionTC_ID"];
                MyDropDown = DropDownList1;
if (flag == "dataset")
        {

            try
            {
                DropDownList MyDropDown = default(DropDownList);
                string TC_ID = null;
                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 + "'";
                    SqlDataAdapter TblAdaptar = new SqlDataAdapter(SQLstring, sqlConn);
                    DataSet Tbl = new DataSet();
                    Tbl.Clear();
                    try
                    {
                        TblAdaptar.Fill(Tbl);
                        MyDropDown.DataSource = Tbl;
                        MyDropDown.DataBind();
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }

Open in new window

LVL 10
GlobaLevelProgrammerAsked:
Who is Participating?
 
afsarsalConnect With a Mentor Commented:
can you give the error description.
Did you add using System.Data; row at the top of page
0
 
GlobaLevelProgrammerAuthor Commented:
here is one:
 ArrayList myArray = new ArrayList();
the type or namespace could not be found(are you missing an directive or namespace reference?)

I believe I am adding the right namespace:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Data.SqlClient;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.Security.Cryptography;
using System.data;
 
 
0
 
Bill NolanOwner, Lead Technology ProgrammerCommented:
You are using a comparison operator and you need to cast object to string.
TC_ID = (string)Session["SessionTC_ID"];

afsaral is probably correct on the other.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Bill NolanOwner, Lead Technology ProgrammerCommented:
Add a reference to the dll.  (Right click 'references' in Solution Explorer.)

Good luck :)
0
 
GlobaLevelProgrammerAuthor Commented:
good suggestion...but im curious why I need to add a reference to the dll , in my vb.net projects I dont have to do this..
0
 
Bill NolanOwner, Lead Technology ProgrammerCommented:
The compiler needs to know where the code for the namespace is.
I don't know if VB somehow automates this.
0
 
rajapandian_81Commented:
Hi,

For Arraylist:
using System.Collections;

Open in new window


For DataSet:
using System.Data;

Open in new window

0
 
Bill NolanOwner, Lead Technology ProgrammerCommented:
So you weren't having an issue with the session var?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.