datagrid not displaying data table data

Discussion in 'ASP .Net' started by .Net Sports, Aug 30, 2005.

  1. .Net Sports

    .Net Sports Guest

    I have a data grid that takes data from a data table, and in
    visualstudio.net, I cannot find the error in the debugger at why I am
    not able to see my datagrid when querying data for a specific date when
    I step thru the code while debugging. ON strSQL when mousing over the
    variable, it indicates its empty. Just can't find where or why it is
    empty.
    Code below (excuse the formatting in this textarea box):



    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here

    DataSet ds = null;
    string strSQL = "";
    SqlMoney totalVolume;
    int repID;
    string LName;

    string QueriedDay = Request.QueryString["thedate"];




    if (!Page.IsPostBack)
    {
    try
    {
    // connect to the database
    string strConn =
    "SERVER=xx.xx.xx.xx;UID=xx;PWD=xxxx;DATABASE=myDB;";
    SqlConnection objConn = new SqlConnection(strConn);
    SqlConnection objConn2 = new SqlConnection(strConn);
    ////-/ get all active salesreps, alias to repID
    string sqlRep = "SELECT SalesRep.ID as repID , SalesRep.LName " +
    "FROM SalesRep " +
    "WHERE (Terminated IS NULL) AND (tblSalesRep.StartDate < '" +
    QueriedDay + "') " +
    "order by SalesRep.ID asc ";

    SqlCommand objCommandDR = new SqlCommand(sqlRep, objConn);
    objConn.Open();
    ///
    ////-/ = SqlCommand.ExecuteReader();
    SqlDataReader drRep = objCommandDR.ExecuteReader();




    // main query

    while (drRep.Read())
    {
    repID = drRep.GetInt32(drRep.GetOrdinal("repID"));
    LName = drRep.GetString(drRep.GetOrdinal("LName"));
    strSQL = "SELECT SalesRep.ID, SalesRep.LName,
    SUM(Accounts.totalsales) AS totalsalesQueriedDay " +
    "FROM SalesRep INNER JOIN " +
    "Orders ON SalesRep.ID = Orders.SalesRep_ID INNER JOIN " +
    "Accounts ON Orders.ID = Accounts.Order_ID " +
    "WHERE Accounts.TDate = '" + QueriedDay + "' AND SalesRep.ID =
    '" + repID + "' " +
    "GROUP BY SalesRep.ID, SalesRep.LName " +
    "HAVING (SUM(Accounts.totalsales) >= 0) " +
    "ORDER BY SalesRep.LName";
    ////-/Debug.WriteLine(strSQL);

    // create an instance of the command-connxt object
    SqlCommand objCommand = new SqlCommand(strSQL, objConn2);
    objConn2.Open();

    SqlDataReader drRevenue = objCommand.ExecuteReader();

    if (drRevenue.Read())
    {
    if
    (drRevenue.IsDBNull(drRevenue.GetOrdinal("totalsalesQueriedDay")))
    {
    totalVolume = 0;
    }
    else
    {
    totalVolume =
    drRevenue.GetSqlMoney(drRevenue.GetOrdinal("totalsalesQueriedDay"));
    }
    }
    else
    {
    totalVolume = 0;
    }




    ////-/DataSet ds = new DataSet( );
    DataTable dt = new DataTable();
    ds.Tables.Add(dt);
    ////-/create columns
    DataColumn dc_repID = new DataColumn("repID",
    System.Type.GetType("System.Int32"));
    DataColumn dc_LName = new DataColumn("LName",
    System.Type.GetType("System.String"));
    DataColumn dc_volume = new DataColumn("totalVolume",
    System.Type.GetType("System.Double"));
    ////-/Add columns to datatable
    dt.Columns.Add(dc_repID);
    dt.Columns.Add(dc_LName);
    dt.Columns.Add(dc_volume);
    ////-/Create a row for each new record found
    objConn2.Close();


    DataRow dr;
    dr = dt.NewRow();
    dr["repID"] = repID;
    dr["LName"] = LName;
    dr["totalVolume"] = totalVolume;
    dt.Rows.Add(dr);


    ////-/ dataset to datagrid bind
    mydatagrid.DataSource = ds;
    mydatagrid.DataBind();


    }
     
    .Net Sports, Aug 30, 2005
    #1
    1. Advertising

  2. .Net Sports

    Marina Guest

    It sounds like the first query isn't returning any rows, so the contents of
    the while loop never get executed.

    ".Net Sports" <> wrote in message
    news:...
    >I have a data grid that takes data from a data table, and in
    > visualstudio.net, I cannot find the error in the debugger at why I am
    > not able to see my datagrid when querying data for a specific date when
    > I step thru the code while debugging. ON strSQL when mousing over the
    > variable, it indicates its empty. Just can't find where or why it is
    > empty.
    > Code below (excuse the formatting in this textarea box):
    >
    >
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > // Put user code to initialize the page here
    >
    > DataSet ds = null;
    > string strSQL = "";
    > SqlMoney totalVolume;
    > int repID;
    > string LName;
    >
    > string QueriedDay = Request.QueryString["thedate"];
    >
    >
    >
    >
    > if (!Page.IsPostBack)
    > {
    > try
    > {
    > // connect to the database
    > string strConn =
    > "SERVER=xx.xx.xx.xx;UID=xx;PWD=xxxx;DATABASE=myDB;";
    > SqlConnection objConn = new SqlConnection(strConn);
    > SqlConnection objConn2 = new SqlConnection(strConn);
    > ////-/ get all active salesreps, alias to repID
    > string sqlRep = "SELECT SalesRep.ID as repID , SalesRep.LName " +
    > "FROM SalesRep " +
    > "WHERE (Terminated IS NULL) AND (tblSalesRep.StartDate < '" +
    > QueriedDay + "') " +
    > "order by SalesRep.ID asc ";
    >
    > SqlCommand objCommandDR = new SqlCommand(sqlRep, objConn);
    > objConn.Open();
    > ///
    > ////-/ = SqlCommand.ExecuteReader();
    > SqlDataReader drRep = objCommandDR.ExecuteReader();
    >
    >
    >
    >
    > // main query
    >
    > while (drRep.Read())
    > {
    > repID = drRep.GetInt32(drRep.GetOrdinal("repID"));
    > LName = drRep.GetString(drRep.GetOrdinal("LName"));
    > strSQL = "SELECT SalesRep.ID, SalesRep.LName,
    > SUM(Accounts.totalsales) AS totalsalesQueriedDay " +
    > "FROM SalesRep INNER JOIN " +
    > "Orders ON SalesRep.ID = Orders.SalesRep_ID INNER JOIN " +
    > "Accounts ON Orders.ID = Accounts.Order_ID " +
    > "WHERE Accounts.TDate = '" + QueriedDay + "' AND SalesRep.ID =
    > '" + repID + "' " +
    > "GROUP BY SalesRep.ID, SalesRep.LName " +
    > "HAVING (SUM(Accounts.totalsales) >= 0) " +
    > "ORDER BY SalesRep.LName";
    > ////-/Debug.WriteLine(strSQL);
    >
    > // create an instance of the command-connxt object
    > SqlCommand objCommand = new SqlCommand(strSQL, objConn2);
    > objConn2.Open();
    >
    > SqlDataReader drRevenue = objCommand.ExecuteReader();
    >
    > if (drRevenue.Read())
    > {
    > if
    > (drRevenue.IsDBNull(drRevenue.GetOrdinal("totalsalesQueriedDay")))
    > {
    > totalVolume = 0;
    > }
    > else
    > {
    > totalVolume =
    > drRevenue.GetSqlMoney(drRevenue.GetOrdinal("totalsalesQueriedDay"));
    > }
    > }
    > else
    > {
    > totalVolume = 0;
    > }
    >
    >
    >
    >
    > ////-/DataSet ds = new DataSet( );
    > DataTable dt = new DataTable();
    > ds.Tables.Add(dt);
    > ////-/create columns
    > DataColumn dc_repID = new DataColumn("repID",
    > System.Type.GetType("System.Int32"));
    > DataColumn dc_LName = new DataColumn("LName",
    > System.Type.GetType("System.String"));
    > DataColumn dc_volume = new DataColumn("totalVolume",
    > System.Type.GetType("System.Double"));
    > ////-/Add columns to datatable
    > dt.Columns.Add(dc_repID);
    > dt.Columns.Add(dc_LName);
    > dt.Columns.Add(dc_volume);
    > ////-/Create a row for each new record found
    > objConn2.Close();
    >
    >
    > DataRow dr;
    > dr = dt.NewRow();
    > dr["repID"] = repID;
    > dr["LName"] = LName;
    > dr["totalVolume"] = totalVolume;
    > dt.Rows.Add(dr);
    >
    >
    > ////-/ dataset to datagrid bind
    > mydatagrid.DataSource = ds;
    > mydatagrid.DataBind();
    >
    >
    > }
    >
     
    Marina, Aug 30, 2005
    #2
    1. Advertising

  3. .Net Sports

    .Net Sports Guest

    Thanks...
    it was a case where the datatable wasnt declared before the sql
    queries.
     
    .Net Sports, Aug 31, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Williams
    Replies:
    2
    Views:
    1,156
    Jacob Yang [MSFT]
    Aug 12, 2003
  2. .Net Sports

    Datagrid footer not displaying data

    .Net Sports, Mar 13, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    3,307
    Ignacio Machin \( .NET/ C# MVP \)
    Mar 13, 2006
  3. _rg_rg_
    Replies:
    3
    Views:
    532
    Toby A Inkster
    Nov 13, 2003
  4. Rio
    Replies:
    4
    Views:
    1,228
  5. Sameer
    Replies:
    1
    Views:
    791
Loading...

Share This Page