Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Object reference not set to an instance of an object

0 views
Skip to first unread message

Bill Cart

unread,
Sep 16, 2003, 7:11:13 PM9/16/03
to
I am very new at this C# stuff. I keep trying to understand it but I don't
seen to have a clue. I am trying to fill a DropDownList from a data adapter.

I have a web application. In the Global.asx I have
private System.Data.SqlClient.SqlConnection sqlConSWT;
private System.Data.SqlClient.SqlCommand sqlCmdAddDemoReq;
private System.Data.SqlClient.SqlDataAdapter sqlDaStates;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private DemoReqSql.dsStates dsStates;


In the web form I have
// redeclare the database stuff in the Global unit
System.Data.SqlClient.SqlCommand sqlCmdAddDemoReq;
System.Data.SqlClient.SqlDataAdapter sqlDaStates;
protected DemoReqSql.dsStates dsTryAgain;
protected System.Web.UI.WebControls.DropDownList DropDownList1;


private void Page_Load(object sender, System.EventArgs e)
{
sqlDaStates.Fill(dsTryAgain);
DropDownList1.DataBind();

Something just like this works in another applications but I can't get this
to go at all. It look just like what is in the book. The error points to the
sqlDaStates.Fill(dsTryAgain); and says "Object reference not set to an
instance of an object". The data set is on the form, do I need to redeclare
it again? Or is there some sort of other error that I should be able to
infer?


Alvin Bruney

unread,
Sep 16, 2003, 10:11:12 PM9/16/03
to
this is bad bad bad. you are holding references to connection objects in
global don't do that
you also are not initializing and opening your connection objects.

i recommend programming ado.net by david scheppa. you need to understand the
basics thoroughly before going on.

"Bill Cart" <bc...@morpc.RemoveThis.org> wrote in message
news:u7VFRfKf...@TK2MSFTNGP12.phx.gbl...

Bill Cart

unread,
Sep 17, 2003, 5:09:53 PM9/17/03
to
Thanks.

The idea for the data stuff to be in the Global comes from the Microsoft
MCAD/MCSD Self Paced Training Kit - Developing Web Applications. The idea is
that if they are declared there they can be used in all of the other
modules. Because I am just starting out I don't understand all of it. I
don't see why they have to be redeclared in the form is they are present in
the Gobal. I have been working with Delphi which has a data module, you just
place things in there and include a reference to it and all of the forms can
access them.

I have tried it both ways (in the Gobal and in the form itself) and I still
can't get it to work. I am basicly copying what they did in the book's
example (which does work) but I must be leaving something out. I have some
C# database books on reserve at the libary, I hope that they can show me
what I should be doing.

"Ignacio Machin" <ignacio.machin_AT_dot.state.fl.us> wrote in message
news:OV37ZHM...@TK2MSFTNGP11.phx.gbl...
> Hi Bill,
>
> These variables needs to be declared in the aspx page, no in the
global.aspx
> , there are no use for then in the global.aspx

> --
> Hope this help,
>
> --
> Ignacio Machin,
> ignacio.machin AT dot.state.fl.us
> Florida Department Of Transportation
>
>


Olaf.B...@skyscan.be

unread,
Sep 25, 2003, 5:56:02 AM9/25/03
to
I have this situtaition.
I want to extract the top most byte from a DWORD (uint in C#).

In C++ I would use some macros like HIBYTE( HIWORD(version)))
Or use another way like byte *ptrByte = (byte*)version; iReturn=ptrByte[3];

So I try to do this in C# using the unsafe, but I get this exception:
e.Message "Object reference not set to an instance of an object." string
Any tips how to do this in a C# style? I also fought with the *fixed*
function but that one has problems between uint* and byte*

The code below compiles.

------------------------------
public int GetVersion() {
int iReturn=-1;
try {
uint version=0x12345678;
unsafe {
byte *ptrByte = (byte*)version;
iReturn=ptrByte[3];
}
} catch (Exception e) {
MessageBox.Show(e.Message, "Critical Error!");
}
return iReturn;
}
}


Andrew Gnenny

unread,
Sep 25, 2003, 6:23:16 AM9/25/03
to
You can use System.Collections.Specialized.BitVector32 to emulate HIBYTE
behavior.

--
Andrew Gnenny
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE


<Olaf.B...@skyscan.be> wrote in message
news:3f72bbb2$0$819$ba62...@reader2.news.skynet.be...

Jon Skeet

unread,
Sep 25, 2003, 7:29:26 AM9/25/03
to
<Olaf.B...@skyscan.be> wrote:
> I have this situtaition.
> I want to extract the top most byte from a DWORD (uint in C#).

Right - forget unsafe code to start with. Don't use unsafe code unless
you've got a very, very good reason to do so. Fortunately, it's very
easy to do what you want:

byte topByte = (byte)(value>>24);

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jon Skeet

unread,
Sep 25, 2003, 7:42:44 AM9/25/03
to
Andrew Gnenny <pulsar2003@/no-spam/email.ru> wrote:
> You can use System.Collections.Specialized.BitVector32 to emulate HIBYTE
> behavior.

You could, indeed - but why not just use plain old-fashioned
bitshifting?

0 new messages