how to solve this error

Posted by Parthibansk under ASP.NET on 4/24/2013 | Points: 10 | Views : 816 | Status : [Member] | Replies : 4
got this error

System.NullReferenceException: Object reference not set to an instance of an object.:

String strConnString = System.Configuration.ConfigurationManager
.ConnectionStrings["CascadingDDLConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("select distinct COntinent from NEWS");
cmd.Connection = con;
con.Open();
ddlcontinent.DataSource = cmd.ExecuteReader();
ddlcontinent.DataTextField = "Continent";
ddlcontinent.DataValueField = "Continent";
ddlcontinent.DataBind();
con.Close();
ddlcontinent.Items.FindByValue(ViewState["Filter"].ToString()).Selected = true;




Responses

Posted by: Brahmam on: 4/24/2013 [Member] Starter | Points: 25

Up
0
Down
String strConnString = System.Configuration.ConfigurationManager
.ConnectionStrings["CascadingDDLConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("select distinct COntinent from NEWS");

above error bold latters error
SqlCommand cmd = new SqlCommand("select distinct COntinent from NEWS");
SqlDataAdapter sda = new SqlDataAdapter(cmd);
cmd.Connection = con;
con.Open();
ddlcontinent.DataSource = cmd.ExecuteReader();
ddlcontinent.DataTextField = "Continent";
ddlcontinent.DataValueField = "Continent";
ddlcontinent.DataBind();
con.Close();
ddlcontinent.Items.FindByValue(ViewState["Filter"].ToString()).Selected = true;

brahmam

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 4/24/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
String strConnString = System.Configuration.ConfigurationManager
.ConnectionStrings["CascadingDDLConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("select distinct COntinent from NEWS");
SqlDataAdapter sda = new SqlDataAdapter(cmd);
cmd.Connection = con;
con.Open();
ddlcontinent.DataSource = cmd.ExecuteReader();
ddlcontinent.DataTextField = "Continent";
ddlcontinent.DataValueField = "Continent";
ddlcontinent.DataBind();
con.Close();
ddlcontinent.Items.FindByValue(ViewState["Filter"].ToString()).Selected = true;

If this post helps you mark it as answer
Thanks

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 4/24/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello You can try this as well

String strConnString = System.Configuration.ConfigurationManager
.ConnectionStrings["CascadingDDLConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
string selectquery = "select distinct Continent from NEWS"
SqlCommand cmd = new SqlCommand(selectquery);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
cmd.Connection = con;
con.Open();
ddlcontinent.DataSource = cmd.ExecuteReader();
ddlcontinent.DataTextField = "Continent";
ddlcontinent.DataValueField = "Continent";
ddlcontinent.DataBind();
con.Close();
ddlcontinent.Items.FindByValue(ViewState["Filter"].ToString()).Selected = true;

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 4/24/2013 [Member] Starter | Points: 25

Up
0
Down
hi
String strConnString = System.Configuration.ConfigurationManager
.ConnectionStrings["CascadingDDLConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
string selectquery = "select distinct Continent from NEWS"
SqlCommand cmd = new SqlCommand(select* from tablename",con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
con.Open();
ddlcontinent.DataSource = cmd.ExecuteReader();
ddlcontinent.DataTextField = "Continent";
ddlcontinent.DataValueField = "Continent";
ddlcontinent.DataBind();
con.Close();
ddlcontinent.Items.FindByValue(ViewState["Filter"].ToString()).Selected = true;

Thanks&Regards

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response