N
.Net Sports
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();
}
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();
}