[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Asp.Net C# Object reference not set to an instance of an object

Asked by homeshopper in Programming for ASP.NET, Microsoft Visual C#.Net

Hi, I am getting the following error:
Object reference not set to an instance of an object.
When I intially run the page it displays a list of databases as per attached '*.jpg' file.
Then I am able to select a database name and it displays the corresponding tables.
But, when I then select a table name it gives the error described below:
The complete code is as per attached code snippet.
Thanks in Advance.
Line 117:        {
Line 118:            Response.Write("dbTableName:" + dbTableName + "  ");
Line 119:            dbTableName = Request.QueryString["tableName"].Trim(' ');
Line 120:        }
Line 121:        string oMyString = null;
 d:\aaaWebaaa\assignmentWebDev\assignmentWebData\app\cmsSchema.aspx.cs
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
//****************************************************************
//cmsSchema.aspx.cs Code behind Page
//****************************************************************
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data.Common;
using System.IO;
using System.Text;
using System.Drawing;
using System.Data.OleDb;
 
public partial class cmsSchema : System.Web.UI.Page
{
    public string sSql;
    public string sDir;
    public bool bDatabaseExists = false;
    public bool bTableExists = false;
    public string sDBServer = System.Net.Dns.GetHostName();
    public string cboSQLServers = System.Net.Dns.GetHostName();
    public string sDataSource = "fuertemon";
    public object sDBServerProvider = "\\sqlexpress";
    public string sUSERid = "sa";
    public string sDBName = "Master";
    public string sDBPass = "h6web97";
    public string TempTable = "Employ";
    public string TempProcedure = "UpdateEmployDetails";
    public string strTable;
    public string strProcedure;
    public SqlConnection connection;
    public string ConnectionString;
    public string MsgBoxDatabase = null;
    public string MsgBoxTable = null;
    public string MessageBox = null;
    public string MessageBoxProcedure = null;
    public DataView Source;
    public DataSet Ds;
    public string sOutput;
    public string strResponse;
    public int i;
    public string tablePage;
    public string dbName;
    public string strCountdb;
    public string dbTableName;
    public string oTableName;
    public string strTbleCount;
    public string odbName;
    public string odbTableName;
    protected void Page_Load(object sender, System.EventArgs e)
    {
        HttpContext _Context = HttpContext.Current;
        if (Page.IsPostBack)
        {
            
        }
        if (!Page.IsPostBack)
        {
            BindGrid();
        }
        //***************************************************************
        //Response.Write("1#" + Request["tablePage"]);
        LabelPage.Text = (Request["tablePage"]);
        //***************************************************************
        SqlConnection sConn = null;
        SqlDataReader sReader = null;
        SqlCommand sComm = null;
        string sMyString = null;
        Session["connStringValue"] = "server=" + sDBServer + sDBServerProvider + ";uid=" + sUSERid + ";pwd=" + sDBPass;
        sMyString = Session["connStringValue"] + ";Initial Catalog=" + sDBName;
        sConn = new System.Data.SqlClient.SqlConnection(Session["connStringValue"].ToString());
        sComm = new System.Data.SqlClient.SqlCommand("Select * from sys.databases WHERE name NOT IN ('master','model','msdb','tempdb')", sConn);
        try
        {
            sConn.Open();
            sReader = sComm.ExecuteReader();
            Repeater1.DataSource = sReader;
            Repeater1.DataBind();
            sReader.Close();
        }
        catch (Exception ex)
        {
            // all other .NET exceptions
            Labelerr.Text = ex.ToString();
        }
        catch
        {
            // all other exceptions
 
        }
        finally
        {
            if (sConn.State != ConnectionState.Closed)
            {
                sConn.Close();
            }
        }
        //***************************************************************
        Init();
        //testDatabase_SelectedIndexChanged(DropDownList1, Nothing)
        //****************************************************************
        if (!(odbName==""));
        {
            Response.Write("odbName:" + odbName + "  ");
            odbName = Request.QueryString["db"].Trim(' ');
        }
        if (!(dbTableName == "")) ;
        {
            Response.Write("dbTableName:" + dbTableName + "  ");
            dbTableName = Request.QueryString["tableName"].Trim(' ');
        }
        string oMyString = null;
        SqlDataReader odbreader = null;
        SqlCommand odbcomm = null;
        int oCounter = 0;
        Session["connStringValue"] = "server=" + sDBServer + sDBServerProvider + ";uid=" + sUSERid + ";pwd=" + sDBPass;
        oMyString = Session["connStringValue"] + ";Initial Catalog=" + odbName;
        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(oMyString);
        SqlConnection odbconn = new SqlConnection(builder.ConnectionString);
        odbconn.Open();
        DataTable tblDatabases = odbconn.GetSchema(SqlClientMetaDataCollectionNames.Tables);
        odbconn.Close();
        ArrayList oItems = new ArrayList();
        ArrayList data = new ArrayList();            
        foreach (DataRow rowDatabase in tblDatabases.Rows)
        {
            if (!(string.IsNullOrEmpty(rowDatabase["table_name"].ToString())))
            {
                builder.InitialCatalog = rowDatabase["table_name"].ToString();
                odbconn.ConnectionString = builder.ConnectionString;
                oItems.Add(rowDatabase["table_name"].ToString());
                //hs.Add("Inv#", "001");
                data.Add(KV("Table:", rowDatabase["table_name"].ToString()));
            }
            oCounter += 1;
        }
        odbconn = new System.Data.SqlClient.SqlConnection(Session["connStringValue"].ToString());
        if (odbconn.State != ConnectionState.Closed)
        {
            odbconn.Close();
        }
        //grid.DataSource = oItems;
        //grid.DataBind();
        repTest.DataSource = data;
        repTest.DataBind();
        //Session["oItems"] = oItems;
        //Session["oCounter"] = oCounter;
        
        //****************************************************************
    }
    // KV for KeyValue is defined as returning an anonymous object:
    private object KV(string Key, string Value)
        {
            return new { Key, Value };
        }
    private static new void Init()
    {
        // initiate variables etc
    }
    protected override void OnInit(EventArgs e)
    {
        //MyBase.OnInit(e);
        //Converted event handler wireups:
        Load += Page_Load;
        //AddHandler DropDownList1.SelectedIndexChanged, AddressOf testDatabase_SelectedIndexChanged
        //AddHandler DropDownList1.SelectedIndexChanged, AddressOf DropDownList1_SelectedIndexChanged
        //AddHandler grid.SelectedIndexChanged, AddressOf grid_SelectedIndexChanged
        //AddHandler empDetails.PageIndexChanging, AddressOf empDetails_PageIndexChanging1
        //AddHandler empDetails.ModeChanging, AddressOf empDetails_ModeChanging
        //AddHandler empDetails.ItemUpdating, AddressOf empDetails_ItemUpdating
        //AddHandler empDetails.ItemUpdated, AddressOf empDetails_ItemUpdated
    }
    public void BindGrid()
    {
        //***************************************************************
 
        //***************************************************************
    }
}
<%
    //*************************************************
    //cmsSchema.aspx Code Page
    //*************************************************
%>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="cmsSchema.aspx.cs" Inherits="cmsSchema" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<link rel="stylesheet" type="text/css" href="../css/outpost.css" />
</head>
<body style="background-image: url(../images/WebFront.jpg); background-repeat:repeat-x">
<!--START PAGE SECTION-->
<table id="table1" style="z-index:101; position:absolute; top:50px; left:5px; width:auto">
<tr>
<td>
<div style="width:900px; height:470px; font-size:smaller; overflow:auto;  border: 0px solid #000000" id="DIV1" onclick="return DIV1_onclick()">
<form id="form1" runat="server">
Heading:1:#
<% 
 for (var i = 0; i <= 5; i++)
{
%>
 <a href="cmsSchema.aspx?tablePage=<%=i%>">[<%=i%>]</a>
<%
}
 
%><a href="../Default.aspx">[Return]</a><br />
Heading:2:#Page:<asp:Label ID="LabelPage" runat="server"></asp:Label><br />
<asp:Repeater id="Repeater1" runat="server">
      <HeaderTemplate>
      </HeaderTemplate>
      <ItemTemplate>
      <a href="cmsSchema.aspx?db=<%# DataBinder.Eval(Container.DataItem, "name")%>">
      <%# DataBinder.Eval(Container.DataItem, "name")%></a>&nbsp;&nbsp;&nbsp; 
      </ItemTemplate>
      <FooterTemplate>
      </FooterTemplate>
      </asp:Repeater><br />
Heading:3:#<br />
<asp:Repeater runat="server" ID="repTest">
    <ItemTemplate>
<a href="cmsSchema.aspx?tableName=<%# DataBinder.Eval(Container.DataItem, "Value")%>">
<%# DataBinder.Eval(Container.DataItem, "Value")%></a>&nbsp;&nbsp;&nbsp; 
<!--
            <%#Eval("Key") %><br />
            <%#Eval("Value") %> 
  -->       
    </ItemTemplate>
</asp:Repeater>
  
<div id="news" class="news" style="float:left;border:1px solid #CCC;padding:.5em;">
<h5 class="headline">Table Data</h5>
<asp:Label ID="Labelerr" runat="server"></asp:Label><br />
<asp:Label ID="detailsLabel" runat="server" />
</div>
</form>
</div>
</td>
</tr>
</table>
<!--END PAGE SECTION CODE-->
</body>
</html>
Attachments:
 
Screen displaying databases and tables
Screen displaying databases and tables
 
[+][-]10/12/09 09:51 AM, ID: 25552810Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/12/09 10:08 AM, ID: 25552931Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/12/09 10:11 AM, ID: 25552949Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/12/09 10:16 AM, ID: 25552988Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/12/09 10:26 AM, ID: 25553099Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/12/09 10:26 AM, ID: 25553105Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/12/09 10:27 AM, ID: 25553114Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/12/09 12:10 PM, ID: 25554065Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/12/09 12:12 PM, ID: 25554075Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/12/09 12:31 PM, ID: 25554229Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/12/09 12:33 PM, ID: 25554250Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/12/09 12:53 PM, ID: 25554403Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/12/09 01:02 PM, ID: 25554472Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/12/09 01:11 PM, ID: 25554541Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Programming for ASP.NET, Microsoft Visual C#.Net
Sign Up Now!
Solution Provided By: burakiewicz
Participating Experts: 1
Solution Grade: A
 
[+][-]10/12/09 01:30 PM, ID: 25554729Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/12/09 01:49 PM, ID: 25554913Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/12/09 02:37 PM, ID: 25555292Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/12/09 03:28 PM, ID: 25555633Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/12/09 03:31 PM, ID: 25555651Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/13/09 06:51 AM, ID: 25559891Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625