473,397 Members | 2,099 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,397 software developers and data experts.

Object null reference



I'm geting a object null reference in this method

SqlConnection cnn = new
SqlConnection("server=(local);database=varired;tru sted_connection=true")
;
SqlCommand cmm = new SqlCommand();
cmm.Connection=cnn;
cnn.Open();
cmm.CommandText="Delete from estados where
id_estado="+Convert.ToInt32(lstEsts.SelectedItem.V alue);

It gives the error in the last line, I don't know what's happening...

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
7 2453
rk
try to get the actual command text during the runtime (thru a
debugger). My guess is that lstEsts.SelectedItem.Value might be
returning the null reference you are getting. So, you might want to
assign the value to a variable and see what you get there.

Good luck!

--rk

Nov 16 '05 #2
Hi Ricardo,

My guess it that the lstEsts contol is supplying the Convert.ToInt32 with a
null value and is throwing a NullReferenceException. If this is what is
happening just make sure that the lstEsts is supplying a value before you
call the Convert method on it. If this is not correct please reply to this
post with more detail of the issue.

I hope this helps.
-----------------------------
Nov 16 '05 #3
either that or there is no selected item!

"rk" <kr*****@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
try to get the actual command text during the runtime (thru a
debugger). My guess is that lstEsts.SelectedItem.Value might be
returning the null reference you are getting. So, you might want to
assign the value to a variable and see what you get there.

Good luck!

--rk

Nov 16 '05 #4
Hi again!

Looking at this more closely you will see another problem when you do get
the control to send you a good value. You will need to use a string or you
will probably get a format exception when you try to concatenate an integer
with a string. I don't know what you are passing the Convert method so
either you will have to call ToString() on it or just forgo the Convert
method completely.

I hope this helps.
---------------------------
"Brian Brown" wrote:
Hi Ricardo,

My guess it that the lstEsts contol is supplying the Convert.ToInt32 with a
null value and is throwing a NullReferenceException. If this is what is
happening just make sure that the lstEsts is supplying a value before you
call the Convert method on it. If this is not correct please reply to this
post with more detail of the issue.

I hope this helps.
-----------------------------

Nov 16 '05 #5


I think it's not returning the selected item... How can this happen???

[]s...

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6
Hi Ricardo,

It is hard to tell without seeing your code. I can only speculate to what
the cause may be. Can you post the code or at least some sample code so the
group may diagnose the problem better?

One quick suggestion. I would check to make sure that the control exists and
is bound before you call its SelectedItem.Value property. Other than that I
would like to see the code.

I hope this helps.
-------------------------
Nov 16 '05 #7


I find the problem.. In the page load event I put the code to populate
the listbox, but forgot the IsPostBack...
So everytime the listbox was populated again, and so no item is
selected...

Thanks to all of you...

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
3
by: Ian Renfrew | last post by:
Does Javascript supply a function that destroys an object? If so, is there a dependancy on Javascript version? Thanks in advance, Ian Renfrew
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
12
by: Joe | last post by:
I might be overworked so please excuse this stupid question... Say I do the following: DataTable table = new DataTable(); myDataAdaptor.Fill(table); dataGrid1.DataSource = table;
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
6
by: Shailen Sukul | last post by:
Observed a weird behaviour with object references. See code listing below: using System; using System.Collections.Generic; using System.Text; namespace PointerExceptionTest { /*
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
6
by: Murray Hopkins | last post by:
Hi. THE QUESTION: How do I get a reference to my Object when processing an event handler bound to an html element ? CONTEXT: Sorry if it is a bit long. I am developing a JS calendar tool....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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...

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.