Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > datagrid not displaying data table data

Reply
Thread Tools

datagrid not displaying data table data

 
 
.Net Sports
Guest
Posts: n/a
 
      08-30-2005
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("totalsal esQueriedDay")))
{
totalVolume = 0;
}
else
{
totalVolume =
drRevenue.GetSqlMoney(drRevenue.GetOrdinal("totals alesQueriedDay"));
}
}
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();


}

 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      08-30-2005
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: ups.com...
>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("totalsal esQueriedDay")))
> {
> totalVolume = 0;
> }
> else
> {
> totalVolume =
> drRevenue.GetSqlMoney(drRevenue.GetOrdinal("totals alesQueriedDay"));
> }
> }
> 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();
>
>
> }
>



 
Reply With Quote
 
 
 
 
.Net Sports
Guest
Posts: n/a
 
      08-30-2005
Thanks...
it was a case where the datatable wasnt declared before the sql
queries.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question: Gridview question (displaying data from a related "many" table) Cirene ASP .Net 1 11-15-2007 05:08 AM
Displaying oracle table in jsp as a html table Sameer Java 1 10-26-2007 01:17 PM
Datagrid footer not displaying data .Net Sports ASP .Net 1 03-13-2006 07:54 PM
Table/table rows/table data tag question? Rio HTML 4 11-05-2004 08:11 AM
Could not load type VTFixup Table from assembly Invalid token in v-table fix-up table. David Williams ASP .Net 2 08-12-2003 07:55 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57