473,322 Members | 1,778 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,322 software developers and data experts.

Class problems

I'm confused about how to declare class variables and accessor pairs. The
following code is my class and the error is below.

If someone could point me in the right direction I'd really appreciate it.

(ps - sorry about the double line posting and lack of indentation)

Rich.

{

public class rkSqlSelect
{

private DataSet rSet;
private SqlCommand cmd;

private DataSet RSet
{
get { return rSet; }
set { rSet = value; }
}

private SqlCommand Cmd
{
get { return cmd; }
set { cmd = value; }
}

// Default constructor
public rkSqlSelect()
{
this.rSet = null;
this.cmd = null;
}

// Constructor - use SQL SELECT query with SqlConnection object
public rkSqlSelect(string sel, SqlConnection conn)
{
this.cmd = new SqlCommand(sel, conn);
this.createDataSet();
}

// Constructor - use SqlCommand
public rkSqlSelect(SqlCommand xcmd)
{
this.cmd = xcmd;
this.createDataSet();
}

private void createDataSet()
{
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = this.cmd;
da.Fill(this.rSet, "resultTable"); // Fails here this.rSet references a
null object
}

public DataTable getDataTable()
{
return this.rSet.Tables["resultTable"];
}

public DataSet getDataSet()
{
return this.rSet;
}
}
}
Value cannot be null. Parameter name: dataSet
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.ArgumentNullException: Value cannot be null.
Parameter name: dataSet

Source Error:

Line 49: SqlDataAdapter da = new SqlDataAdapter();
Line 50: da.SelectCommand = this.cmd;
Line 51: da.Fill(this.rSet, "resultTable"); // Fails here this.rSet
references a null object
Line 52: }
Line 53:
Nov 16 '05 #1
2 1053
KavvY <k@u.r> wrote:
I'm confused about how to declare class variables and accessor pairs. The
following code is my class and the error is below.

If someone could point me in the right direction I'd really appreciate it.


Well, you haven't shown where rSet is meant to be set to a reference to
an actual dataset, instead of being null...

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

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
KavvY <k@u.r> wrote:
I'm confused about how to declare class variables and accessor pairs. The following code is my class and the error is below.

If someone could point me in the right direction I'd really appreciate
it.
Well, you haven't shown where rSet is meant to be set to a reference to
an actual dataset, instead of being null...

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

\Slaps head

Thanks!

Of course, I have to create a new DataSet instance and make it reference
rSet in the constructor.

Cheers.
Nov 16 '05 #3

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

Similar topics

15
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for...
8
by: Ares Lagae | last post by:
When adopting the coding style of the standard C++ library, you often run into naming problems because class names are lower case, and member functions do not have get/set prefixes. For example:...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
9
by: MLH | last post by:
I need a fundamental explanation of Class Modules - something suitable for newbies. Access 2.0 didn't seem to focus on them very much. Now that I'm using Access 97, it seems they're everywhere. thx...
1
by: Anders Berg | last post by:
Hi! I'm developing a very simple chat application in VB.NET and I've stumbled into a problem. For simplicity I'm using the TcpListener and TcpClient classes. However, at one point I discovered...
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
9
by: Rudy | last post by:
Hello All! I'm a little confused on Public Class or Modules. Say I have a this on form "A" Public Sub Subtract() Dim Invoice As Decimal Dim Wage As Decimal Static PO As Decimal Invoice =...
12
by: Janaka Perera | last post by:
Hi All, We have done a object oriented design for a system which will create a class multiply inherited by around 1000 small and medium sized classes. I would be greatful if you can help me...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
1
by: flowstudioLA | last post by:
I have a template class object that I use as a mesaging queue between threads. I use it as a static object that I initialize like so: foo.h class foo{ static LFQueue<const char*,100lfqMyQueue;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.