You never initiated the batches class member. Somewhere, you need to have:
batches = new SqlDataSource();
I'd put it right before setting the connection string.
~~Bonnie
>I appreciate the help:
>
>Here is my object:
>
>public class HospitalBatch
>{
> public string hospid;
> public string hospital;
> public SqlDataSource batches;
>}
>
>Here is my method to fill it:
>
>public HospitalBatch GetHospitalBatches(string name, string hospital)
> {
> HospitalBatch b = new HospitalBatch();
>
> SqlConnection myConn = new SqlConnection(connection);
> SqlCommand myCmd = new SqlCommand("select hospid,company from arcust where company = '" + hospital.Trim().ToUpper() + "'", myConn);
> myConn.Open();
> SqlDataReader sdr = myCmd.ExecuteReader();
>
> while (sdr.Read())
> {
> b.hospid = sdr["hospid"].ToString().Trim();
> b.hospital = sdr["company"].ToString().Trim();
> }
>sdr.Close();
>myConn.Close();
>
>b.batches.ConnectionString = connection;
>b.batches.SelectCommand = "select hospid,company from arcust where company = '" + hospital.Trim().ToUpper() + "'";
>b.batches.ID = "MySource";
>name.Trim().ToUpper() + "' and hospid = '" + b.hospid.Trim() + "'");
>return b;
>
>Here is my call from the presentation layer:
>
>HospitalBatch batch = new HospitalBatch();
>GetBatches getBatches = new GetBatches();
>batch = getBatches.GetHospitalBatches(Session["name"].ToString().ToUpper().Trim(),DropDownList1.SelectedItem.Text);
>
>which results in the error: Object reference not set to an instance of an object...
>
>This has been driving me nuts, this is the first time I've worked with the SQLdatasource as well. Thanks for the help!