473,466 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DataSource is Nothing (Error)

77 New Member
Hi All,
This is my code:
Expand|Select|Wrap|Line Numbers
  1.  If dgTransaction.DataSource.Equals(Nothing) Then
  2.             Dim i As Integer
  3.             For i = 0 To dgTransaction.Rows.Count - 1
  4.                 dt.Rows.Add(dgTransaction.Rows(i))
  5.             Next
  6.  
  7.         End If
and I get this error:
Object reference not set to an instance of an object.

I can see in Watch window that dgTransaction.DataSource=Nothing. what should I do?
Aug 19 '08 #1
6 1217
Curtis Rutland
3,256 Recognized Expert Specialist
Try:
Expand|Select|Wrap|Line Numbers
  1. If dgTransaction.DataSource = Nothing Then
Also, I've had to add code tags to several of your posts. Please use the # button in the editor to put CODE tags around your code snippets.

Mod.
Aug 19 '08 #2
Sep410
77 New Member
I am so sorry for the tags.Thanks for your help.
Aug 19 '08 #3
Sep410
77 New Member
In the same code :
Expand|Select|Wrap|Line Numbers
  1. If dgTransaction.DataSource = Nothing Then
  2.             Dim i As Integer
  3.             Dim j As Integer
  4.             For i = 0 To dgTransaction.Rows.Count - 1
  5.                 Dim temp(23) As Object
  6.                 For j = 0 To 23
  7.                     temp(j) = dgTransaction.Rows(i).Cells(j).Value
  8.                 Next
  9.                 dt.Rows.Add(temp)  *****
  10.            Next
I get this error on***** line:
Object reference not set to an instance of an object.
What is wrong here?
Aug 19 '08 #4
Curtis Rutland
3,256 Recognized Expert Specialist
Perhaps dgTransaction = Nothing

Check for that first.
Aug 19 '08 #5
Sep410
77 New Member
I know it has 2 rows.
Aug 19 '08 #6
Curtis Rutland
3,256 Recognized Expert Specialist
Well, you can take the easy way out, and wrap the code in a Try Catch block. Handle that specific exception like you would handle the if statement evaluating to true.

But there's something that's null (nothing) there that's causing the problem. You should really try to find it.
Aug 19 '08 #7

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

Similar topics

0
by: Jon Brunson | last post by:
I've got a very weird problem, when I run the following code the ComboBox (Me.cmbInputDevice) is always empty. The ComboBox is on a UserControl in a Class Library. I'm using VS.NET 2003 with...
0
by: Jon Brunson | last post by:
I've got a very weird problem, when I run the following code the ComboBox (Me.cmbInputDevice) is always empty. The ComboBox is on a UserControl in a Class Library. I'm using VS.NET 2003 with...
11
by: Zorpiedoman | last post by:
The problem is this: I have a list box. I set an array list as the datasource. I remove an item from the array list. I set the listbox datasource to nothing. I set the listbox datasource to...
0
by: Jon Brunson | last post by:
I've got a very weird problem, when I run the following code the ComboBox (Me.cmbInputDevice) is always empty. The ComboBox is on a UserControl in a Class Library. I'm using VS.NET 2003 with...
3
by: balaki | last post by:
Hi, I am working on a Installer Project, which requires to deploy SQL Server 2005 Reports (.rdl files) and Datasource (.rds file). The datasource is common for all reports. The report files are...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.