I want to populate a dropdownlist from database in code behind. I tried with the following code but while binding it is throwing an error "Object Reference not set to an Instance". Please find the code appended.Thanks in advance.
Code:
Sample.aspx:
Sample.aspx.cs
System.Data.SqlClient.SqlConnection conn = null;
SqlDataReader drFailureCode = null;
string sqlQuery = string.Empty;
System.Data.SqlClient.SqlConnection conn = null;
SqlDataReader drFailureCode = null;
string sqlQuery = string.Empty;
sqlQuery = "select distinct * from
conn = SqlHelperConnection.getConnection();
drFailureCode = SqlHelper.ExecuteReader(conn, CommandType.Text, sqlQuery);
if (drFailureCode.HasRows)
{
ddlSample.DataSource = drFailureCode;
ddlSample.DataTextField = "FailureID";
ddlSample.DataValueField = "FailureName";
ddlSample.DataBind();
}
drFailureCode.Close();
ddlSample.Items.Insert(0, new ListItem("--Select--", "0"));
Thanks In Advance.
Sukesh MarlaPosted Aug 12, 2012, 4:23 AM
U just try by that way and by that you may get reason for the actual error.
Hope It Helped. Please Check This is Currect Answer.
Naresh AvariPosted Aug 12, 2012, 4:20 AM
Sukesh MarlaPosted Aug 12, 2012, 4:20 AM
vijay ragsPosted Aug 12, 2012, 3:56 AM
Sukesh MarlaPosted Aug 12, 2012, 3:31 AM
vijay ragsPosted Aug 12, 2012, 3:29 AM
Sukesh MarlaPosted Aug 12, 2012, 3:19 AM
Hope It Helped. Please Check This is Currect Answer.