473,657 Members | 2,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Object reference not set to an instance of an object.".....er ror

5 New Member
hi,
i write the following code to get a specific data row from the data set.but it generates the
"Object reference not set to an instance of an object.".....er ror
private void showClientListF orUser()
{
string[] fkeys = new string[2];

fkeys[0] = txtUserName.Tex t;
fkeys[1] = txtUserCompanyN umber.Text;

DataSet ds = new DataSet();
DataRow dr = null;

for (int i = 0; i < dsMain.Tables["UserClient "].Rows.Count; i++)
{
dr[i] = dsMain.Tables["UserClient "].Select("UserID ="+"'"+fkeys[0]+"'"+ "and CompNo= " + fkeys[1]);

// dr = ds.Tables[0].Rows[i];
lvwClientsForUs er.Items.Add(Co nvert.ToString( dr["CompNo"]));
lvwClientsForUs er.Items[i].SubItems.Add(C onvert.ToString (dr["ClientNo"]));
lvwClientsForUs er.Items[i].SubItems.Add(C onvert.ToString (dr["CNAME"]));
}
}
if anyone can help me to correct this error?
Sep 27 '07 #1
5 2323
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
for starters,
Please put your code between the [code] Tags
Second, your probably have about 20 lines there....which line and which object threw that error is unknown !!

PLease state them clearly and it woiuld be helpful

cheers
Sep 27 '07 #2
piyumi80
5 New Member
for starters,
Please put your code between the [code] Tags
Second, your probably have about 20 lines there....which line and which object threw that error is unknown !!

PLease state them clearly and it woiuld be helpful

cheers
dr[i] = dsMain.Tables["UserClient "].Select("UserID ="+"'"+fkeys[0]+"'"+ "and CompNo=" + fkeys[1]);//this line throws the error
Sep 27 '07 #3
Strika Amaru
19 New Member
Firstly:
Expand|Select|Wrap|Line Numbers
  1.      private void showClientListForUser()
  2.         {
  3.             string[] fkeys = new string[2];
  4.  
  5.             fkeys[0] = txtUserName.Text;
  6.             fkeys[1] = txtUserCompanyNumber.Text;
  7.  
  8.             DataSet ds = new DataSet();
  9.             DataRow dr = null;
  10.  
  11.             for (int i = 0; i < dsMain.Tables["UserClient"].Rows.Count; i++)
  12.             {
  13.                 dr[i] = dsMain.Tables["UserClient"].Select("UserID="+"'"+fkeys[0]+"'"+ "and CompNo= " + fkeys[1]); // err
  14.  
  15.               //  dr = ds.Tables[0].Rows[i];
  16.                 lvwClientsForUser.Items.Add(Convert.ToString(dr["CompNo"]));
  17.                 lvwClientsForUser.Items[i].SubItems.Add(Convert.ToString(dr["ClientNo"]));
  18.                 lvwClientsForUser.Items[i].SubItems.Add(Convert.ToString(dr["CNAME"]));
  19.             }
  20.         }
Secondly: This is a pretty weird one; at first glance, it would seem that dsMain.Tables["UserClient "] doesn't exist, so Select gets called on a null reference; but within the for, .Rows.Count gets called without any problems. If I were in your place, I'd run a debug session to figure out exactly what's going on in there.
Sep 27 '07 #4
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
that is becuase before the for loop u declared dr = null
and in the first statement in your for loop you are trying to assign dr[i]
when dr itself is null, dr[i] will definitely throw errors :)

cheers
Sep 27 '07 #5
Plater
7,872 Recognized Expert Expert
They're right, you never assign anything to your DataRow dr.
So Instead of:
Expand|Select|Wrap|Line Numbers
  1. dr[i]=
  2.  
Try using:
Expand|Select|Wrap|Line Numbers
  1. dsMain.Tables["UserClient"].Rows[i]=
  2.  
Sep 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2742
by: Bob Cannistraci | last post by:
A three-tier user authentication system was running without a problem for almost a year and now is suddenly dysfunctional. We don't know of any changes to any of the servers. It's quite maddening. The details: 1) We know the COM+ app is instanced on the COM+ server (Win 2000). The component graphic spins when CreateObject is called. 2) The proxy is installed on an IIS server (Win 2000) with delivers the interface, written in ASP, to the...
1
6041
by: vijay | last post by:
Hi I am working on a web application. I have huge form where in I have filled some part of the form and after two hours again I started filling the rest of the form but I got the following error Server Error in '/abc' Application Server Error in '/abc' Application >> Object reference not set to an instance of an object. >> Description: An unhandled exception occurred during the execution o >> the current web request. Please review...
1
2822
by: Chris Magoun | last post by:
I suddenly received an unexpected error in my project. I have been working on this project for some time without this issue. Nothing has changed in the form that caused the exception. A little experimentation shows that I cannot run ANY .NET web project without getting this error: ---------------------------------------------------------------------------- ---- Object reference not set to an instance of an object.
18
28742
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 0, 0) Why is this? Marc
9
5107
by: MrSpock | last post by:
1. Create a new Windows Application project. 2. Open the project properties and check "Make single instance application". 3. Build. 4. Go to the release folder and run the application. 5. Try to open a second instance of the application. This will cause an unhandled exception and the "Send Error Report" box shows up. Does this happen to anyone else, or is it just me? Debug info: "Unhandled exception at 0x00e149fd in...
1
2500
by: DaveO. | last post by:
Hello, I'm calling a VB.NET web service, also from VB.NET, and I get the error " Object reference not set to an instance of an object" on the following line in Reference.vb, when it tries to make the call: Dim results() As Object = Me.Invoke("Phys_Post", New Object() {SessionID, a, b, c, d, CountList}) I can call other web services I've written just fine. This one is more
2
2973
by: louie.hutzel | last post by:
This JUST started happening, I don't remember changing any code: When I click the submit button on my form, stuff is supposed to happen (which it does correctly) and a result message is posted back to the same page at the top of my form alerting the user that their request has been approved or denied. However, the end result is an error message: Error Message: Object reference not set to an instance of an object.
0
2213
by: =?Utf-8?B?SkhhbGV5?= | last post by:
Our system is: IIS Server: dual Intel Xeon 2.80 GHz, 4 GB Ram Windows Server 2003 SP2 IIS 6.0 SQL Server: dual Intel Xeon 2.80 GHz, 4 GB Ram (separate server) Windows Server 2003 SP2 SQL Server 2000 We are having some problems with a website we are developing, and had some
0
2645
by: Tamer Ibrahim | last post by:
Hi, Sometimes, I got the following error message when I use ajax calendar control on some aspx pages : 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...
2
2188
by: Monty | last post by:
I'm installing an ASP.Net 2.0 web applications project (WAP) application on a production server (Win 2003). I've installed it on XP test machines before and it runs fine. On my production machine I get this error (full error screen below) when I attempt to visit the start page. The type ("MyCo.Ing.MyAppRoleProvider") is in my main assembly in the \bin folder. Can anyone tell me what I'm doing wrong or what I should check? TIA. Server...
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.