Class problems

K

KavvY

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:
 
J

Jon Skeet [C# MVP]

KavvY said:
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...
 
K

KavvY

Jon Skeet said:
it.

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


\Slaps head

Thanks!

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

Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top