I have a DataClassLibrary I use for the connectionString and then I also have the C# code behind the ASP page. I want to be able to use While(reader.read()) in my ASP page so that I can get the multiple values the reader returns. How can I go about implementing this? I have provided the code below for my Data Class and the ASP page.
Data Class:
reader = DBHelper.executeQuery(dbConn, sqlString.ToString(), parameters);
if (reader != null)
{
if (reader.Read())
{
OrderID = (int)Convert.ToInt32(reader["OrderID"]);
CaseNum6 = (int)Convert.ToInt32(reader["CaseNum6"]);
CaseNum9 = (int)Convert.ToInt32(reader["CaseNum9"]);
Group = (int)Convert.ToInt32(reader["Group"]);
Completed = (bool)reader["Completed"];
}
else
throw new Exception("No record returned");
reader.Close();
reader.Dispose();
dbConn.Close();
dbConn.Dispose();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (dbConn != null)
{
try { dbConn.Close(); dbConn.Dispose(); }
catch { }
}
if (reader != null)
{
try { reader.Close(); reader.Dispose(); }
catch { }
}
}
ASP page to implement on:
LineAData NewDataA = new LineAData();
LineAData NewDataB = new LineAData();
string connString = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
NewDataA.load(1,3);
NewDataB.load(2,3);
L1.Text = NewDataA.CaseNum6.ToString();
L2.Text = NewDataA.CaseNum9.ToString();
L7.Text = NewDataA.CaseNum6.ToString();
L8.Text = NewDataA.CaseNum9.ToString();
L4.Text = NewDataB.CaseNum6.ToString();
L5.Text = NewDataB.CaseNum9.ToString();
L10.Text = NewDataB.CaseNum6.ToString();
L11.Text = NewDataB.CaseNum9.ToString();
}
I did not understand your question well, but as far as i understood. I think you require the multiple values from the reader on your asp page. If this is the requirement then what you can do is, just create one class which will contain all the column name which will be there in the reader.
The method which is there in your DataClassLibrary will return the List.
The below example will help you:
On ASPX page:
just create the object of the class in which this method is there. and get it. Suppose it is there in the cUser class.
I hope it will help you.. :)