473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

handle exception error in listview

25
Hi everybody,

Actually I'm trying to do small form that has a textbox for BARCODE which when I scan an item it will add on my listview but I recieved this error that I don't know what went wrong in my code

"System.NullReferenceException: Object reference not set to an instance of an object."


Expand|Select|Wrap|Line Numbers
  1. private void text1_down(object sender, KeyEventArgs e)
  2.         {
  3.             if (e.KeyCode == Keys.Enter)
  4.             {
  5.  
  6.  
  7.                 try
  8.                 {
  9.  
  10.                     OracleDataAdapter xx = new OracleDataAdapter("SELECT * FROM POS WHERE barcode = " + this.textBox1.Text, conn);
  11.                     ww = cmnd.ExecuteReader();
  12.                     DataSet DS = new DataSet();
  13.                     xx.Fill(DS, "pos");
  14.                     DataTable dtable = DS.Tables["pos"];
  15.  
  16.                     // Display items in the ListView control
  17.                     for (int i = 0; i < dtable.Rows.Count; i++)
  18.                     {
  19.                         DataRow drow = dtable.Rows[i];
  20.  
  21.                         // Only row that have not been deleted
  22.                         if (drow.RowState != DataRowState.Deleted)
  23.                         {
  24.                             // Define the list items
  25.                             ListViewItem lvi = new ListViewItem(drow["product_name"].ToString());
  26.                             lvi.SubItems.Add(drow["price"].ToString());
  27.  
  28.                             // Add the list items to the ListView
  29.                             listView2.Items.Add(lvi);
  30.                         }
  31.                     }
  32.  
  33.                 }
  34.  
  35.                 catch (Exception error)
  36.                 {
  37.                     MessageBox.Show(error.ToString());
  38.                 }
  39.             }
  40.         }
  41.  


Could anyone help me to fix this code
Jan 20 '12 #1
2 2153
PsychoCoder
465 Expert Mod 256MB
What line does the error occur on. Set a breakpoint on line 3 and use F11 to step through your code to find out where the error is occurring.
Jan 20 '12 #2
RomeoX
25
First of all, thank you very much for replying to my topic. Actually I changed the code to use the button instead of barcode, it mentioned the error in line 74 which is FOR loop line seems doesn't catch the any thing from the database,

for (int i = 0; i < dtable.Rows.Count; i++)

Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             try
  4.             {
  5.  
  6.                 OracleDataAdapter xx = new OracleDataAdapter("Select * From localpos where brcod = 6281014472210", conn);
  7.                 DataSet DS = new DataSet();
  8.                 xx.Fill(DS);
  9.                 DataTable dtable = DS.Tables["localpos"];
  10.  
  11.                 // Display items in the ListView control
  12.                 for (int i = 0; i < dtable.Rows.Count; i++)
  13.  
  14.                 {
  15.                     DataRow drow = dtable.Rows[i];
  16.  
  17.                     // Only row that have not been deleted
  18.                     if (drow.RowState != DataRowState.Deleted)
  19.                     {
  20.                         // Define the list items
  21.                         ListViewItem lvi = new ListViewItem(drow["p_name"].ToString());
  22.                         lvi.SubItems.Add(drow["p_price"].ToString());
  23.  
  24.                         // Add the list items to the ListView
  25.                         listView2.Items.Add(lvi);
  26.                     }
  27.                 }
  28.  
  29.             }
  30.  
  31.             catch (Exception er)
  32.             {
  33.                 MessageBox.Show(er.ToString());
  34.             }
  35.         }
Jan 20 '12 #3

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

Similar topics

0
by: Fiona McBride | last post by:
Hi all, I have a really odd problem with some Visual Basic .NET 2003 code; I have a program that creates a number of windows which contain RichTextBox, Timers (disabled) and menus. The code...
4
by: tarmat | last post by:
I have a class that has a std::list of ints as a member. Let's say its this: std::list<int> MyInts; Frequently, another list of ints is assigned to MyInts MyInts = MyOtherInts; This...
3
by: Ed Robichaud | last post by:
I'm temporarily stumped on how to handle/suppress an error (2501) if a user cancels sending an email. I'm using DoCmd.SendObject to trigger an Outlook send window, which works OK, but if the msg...
1
by: Abby | last post by:
Hi ... when I run my program, it produces error. I would like to know how to handle this error message. I don't want to see it on screen. Any way to just ignore it? Please let me know. Thanks a...
1
by: Mech | last post by:
I am trying to connect to a simple Access Database on my c drive. I am using Windows 2000 pro; nothing special. the following code produces a security exception error. Why? string ConnStr =...
6
by: Paul | last post by:
Hello, The following code generates an exception error the *second* time it is called. Can anyone see what I'm doing wrong? There is a similar example in Wrox Professional VB.NET Page 289. ...
9
by: Ron | last post by:
my application is throwing an exception error when closing if I run a procedure in the app. I can't even trap the error with try/catch ex As Exception. Is there a way to completely shut down the...
8
by: Philip Colmer | last post by:
I'm rewriting some existing VBScript into VB.Net code. It was all going well until I hit the following error when testing the code: System.Runtime.InteropServices.COMException (0x80041003) at...
1
by: zeeshansohail | last post by:
Hi, I am facing a problem. As i don't know, how to handle EXCEPTION in ORACLE (PL/SQL). Please if someone can help me to solve out this problem. I will be grateful to him/her. Wating for...
2
by: shivp | last post by:
Hi, I'm getting folowing exception error while compiling the code in VS2005. $exception {Unable to evaluate expression because the code is optimized or a native frame is on top of the call...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
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
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...
0
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...

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.