Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 33: string value = row["Database_Name"] + ""; Line 34: parentNode.ChildNodes.Add(new TreeNode(value)); Line 35: lv.Items.Add(value);//HERE ERROR COME RED Line 36: Line 37:
protected void Page_Load(object sender, EventArgs e) { welcome.InnerText = Session["name"].ToString(); if (!Page.IsPostBack) { SqlConnection cnn = new SqlConnection("Data Source=HAMEED_KHAN\\SQLEXPRESS;Initial Catalog=db_compiler;Integrated Security=True"); SqlCommand cmd = new SqlCommand("SELECT Database_Name FROM Create_db", cnn); DataTable dt = new DataTable(); Master.FindControl("TreeView1"); TreeView tv = (TreeView)Master.FindControl("TreeView1"); ListBox lv = (ListBox)Master.FindControl("ListBox1"); SqlDataAdapter da = new SqlDataAdapter(cmd); cnn.Open(); da.Fill(dt); cnn.Close(); var parentNode = new TreeNode("Database"); if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { string value = row["Database_Name"] + ""; parentNode.ChildNodes.Add(new TreeNode(value)); lv.Items.Add(value); } } tv.Nodes.Add(parentNode); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)