473,856 Members | 1,595 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 2350
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
2758
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
6081
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
2835
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
28765
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
5117
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
2515
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
2981
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
2222
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
2659
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
2208
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
9918
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
10389
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9532
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7932
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
7097
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5762
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...
1
4578
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4175
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3202
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.