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