Hi all, I want to retrieve some data from the database and return as a datatable.
However, it does not work. I tried both methods that I could find in the Internet, but it's not working. May I know what have I done wrong? The datatable is returned as null {} .
public static DataTable retrieveView2(string pID)
{
SqlConnection conn = new SqlConnection(connString);
SqlCommand comm = new SqlCommand(
"Select apname, designation, email, watcherEmail, e.status, reason, responsedate "
+ "from aparty ap, estatus e, endpack ep "
+ "where ap.projectid = ep.projectid "
+ "and e.apid = ap.apid "
+ "and ap.ep = 't' "
+ "and e.status !='Pending' "
+ "and ep.status ='Completed' "
+ "and e.projectID = @pID");
comm.Connection = conn;
conn.Open();
comm.Parameters.AddWithValue("@pID", pID);
SqlDataReader dr = comm.ExecuteReader();
DataTable dt = new DataTable();
//method 1
dt.load(dr);
//method 2
//while (dr.Read())
//{
// DataRow row = dt.NewRow();
// row["apname"] = dr["apname"].ToString();
//continue other rows.
// dt.Rows.Add(row);
//}
conn.Close();
return dt;
}
By the way, I will prefer to present the data similiar like SQLServer.
Something like that
column/row | apname | designation | email | watcherEmail | status | reason | responsedate
row 1 | name1 | designation1 | email1 | watcherEmail1 | status1 | reason1 | responsedate1
row 2 | name2 | designation2 | email2 | watcherEmail2 | status2 | reason2 | responsedate2
Please help thanks!