I have a data grid that takes data from a data table, and in
visualstudio.ne t, 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(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
DataSet ds = null;
string strSQL = "";
SqlMoney totalVolume;
int repID;
string LName;
string QueriedDay = Request.QuerySt ring["thedate"];
if (!Page.IsPostBa ck)
{
try
{
// connect to the database
string strConn =
"SERVER=xx.xx.x x.xx;UID=xx;PWD =xxxx;DATABASE= myDB;";
SqlConnection objConn = new SqlConnection(s trConn);
SqlConnection objConn2 = new SqlConnection(s trConn);
////-/ get all active salesreps, alias to repID
string sqlRep = "SELECT SalesRep.ID as repID , SalesRep.LName " +
"FROM SalesRep " +
"WHERE (Terminated IS NULL) AND (tblSalesRep.St artDate < '" +
QueriedDay + "') " +
"order by SalesRep.ID asc ";
SqlCommand objCommandDR = new SqlCommand(sqlR ep, objConn);
objConn.Open();
///
////-/ = SqlCommand.Exec uteReader();
SqlDataReader drRep = objCommandDR.Ex ecuteReader();
// main query
while (drRep.Read())
{
repID = drRep.GetInt32( drRep.GetOrdina l("repID"));
LName = drRep.GetString (drRep.GetOrdin al("LName"));
strSQL = "SELECT SalesRep.ID, SalesRep.LName,
SUM(Accounts.to talsales) AS totalsalesQueri edDay " +
"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.t otalsales) >= 0) " +
"ORDER BY SalesRep.LName" ;
////-/Debug.WriteLine (strSQL);
// create an instance of the command-connxt object
SqlCommand objCommand = new SqlCommand(strS QL, objConn2);
objConn2.Open() ;
SqlDataReader drRevenue = objCommand.Exec uteReader();
if (drRevenue.Read ())
{
if
(drRevenue.IsDB Null(drRevenue. GetOrdinal("tot alsalesQueriedD ay")))
{
totalVolume = 0;
}
else
{
totalVolume =
drRevenue.GetSq lMoney(drRevenu e.GetOrdinal("t otalsalesQuerie dDay"));
}
}
else
{
totalVolume = 0;
}
////-/DataSet ds = new DataSet( );
DataTable dt = new DataTable();
ds.Tables.Add(d t);
////-/create columns
DataColumn dc_repID = new DataColumn("rep ID",
System.Type.Get Type("System.In t32"));
DataColumn dc_LName = new DataColumn("LNa me",
System.Type.Get Type("System.St ring"));
DataColumn dc_volume = new DataColumn("tot alVolume",
System.Type.Get Type("System.Do uble"));
////-/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["totalVolum e"] = totalVolume;
dt.Rows.Add(dr) ;
////-/ dataset to datagrid bind
mydatagrid.Data Source = ds;
mydatagrid.Data Bind();
} 2 1978
It sounds like the first query isn't returning any rows, so the contents of
the while loop never get executed.
".Net Sports" <ba********@cox .net> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com... I have a data grid that takes data from a data table, and in visualstudio.ne t, 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(objec t sender, System.EventArg s e) { // Put user code to initialize the page here
DataSet ds = null; string strSQL = ""; SqlMoney totalVolume; int repID; string LName;
string QueriedDay = Request.QuerySt ring["thedate"];
if (!Page.IsPostBa ck) { try { // connect to the database string strConn = "SERVER=xx.xx.x x.xx;UID=xx;PWD =xxxx;DATABASE= myDB;"; SqlConnection objConn = new SqlConnection(s trConn); SqlConnection objConn2 = new SqlConnection(s trConn); ////-/ get all active salesreps, alias to repID string sqlRep = "SELECT SalesRep.ID as repID , SalesRep.LName " + "FROM SalesRep " + "WHERE (Terminated IS NULL) AND (tblSalesRep.St artDate < '" + QueriedDay + "') " + "order by SalesRep.ID asc ";
SqlCommand objCommandDR = new SqlCommand(sqlR ep, objConn); objConn.Open(); /// ////-/ = SqlCommand.Exec uteReader(); SqlDataReader drRep = objCommandDR.Ex ecuteReader();
// main query
while (drRep.Read()) { repID = drRep.GetInt32( drRep.GetOrdina l("repID")); LName = drRep.GetString (drRep.GetOrdin al("LName")); strSQL = "SELECT SalesRep.ID, SalesRep.LName, SUM(Accounts.to talsales) AS totalsalesQueri edDay " + "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.t otalsales) >= 0) " + "ORDER BY SalesRep.LName" ; ////-/Debug.WriteLine (strSQL);
// create an instance of the command-connxt object SqlCommand objCommand = new SqlCommand(strS QL, objConn2); objConn2.Open() ;
SqlDataReader drRevenue = objCommand.Exec uteReader();
if (drRevenue.Read ()) { if (drRevenue.IsDB Null(drRevenue. GetOrdinal("tot alsalesQueriedD ay"))) { totalVolume = 0; } else { totalVolume = drRevenue.GetSq lMoney(drRevenu e.GetOrdinal("t otalsalesQuerie dDay")); } } else { totalVolume = 0; }
////-/DataSet ds = new DataSet( ); DataTable dt = new DataTable(); ds.Tables.Add(d t); ////-/create columns DataColumn dc_repID = new DataColumn("rep ID", System.Type.Get Type("System.In t32")); DataColumn dc_LName = new DataColumn("LNa me", System.Type.Get Type("System.St ring")); DataColumn dc_volume = new DataColumn("tot alVolume", System.Type.Get Type("System.Do uble")); ////-/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["totalVolum e"] = totalVolume; dt.Rows.Add(dr) ;
////-/ dataset to datagrid bind mydatagrid.Data Source = ds; mydatagrid.Data Bind();
}
Thanks...
it was a case where the datatable wasnt declared before the sql
queries. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Diego TERCERO |
last post by:
Hi...
I'm working on a tool for editing text resources for a family of software
product my company produces.
These text resources are found in a SQL Server database, in a table called
"Resource" with the following structure :
Resource{,en,fr,es}
Yes.. these are the only languages supported actually.
A couple of rows in that table would look like this :
|
by: VM |
last post by:
When I display data to a Windows datagrid I usually fill the underlying
table (in another class) and then, once it contains all the data, I attach
it to the grid. But there are some processes that involve large amounts of
data so the user won't be able to see anything in the grid until after the
table's already filled up (usually 40-60 secs with these large processes).
Is it possible (without changing the process of filling the table...
|
by: Jeff |
last post by:
IDE: VS 2003 :NET
OS: XP Pro
My app have a form with a tab-control on it. The tab-control have 2
tabpages. One of the tabpages displays a datagrid, and the other tabpage
displays details (order date, name, address etc) about the selected row in
the datagrid...
My problem is when I enter a new record in the details tabpage (saves data
to database), and go back to the datagrid. Only the data from the PM-table
|
by: Shawn |
last post by:
Hi.
I already have a datagrid where I'm using paging. I have a stored procedure
that fills a temp table with 200-500 rows and then sends back 10 records at
the time. When I go to page 2 the SP fills the temp table again and returns
rows 10-19. The temp table is dropped after each call to the SP, so it has
to be created and filled every time the user changes page in the datagrid.
My question is this: Would it be more efficient to...
|
by: latin & geek via DotNetMonster.com |
last post by:
hi!
ok, im working on a database application. ive successfully managed to
establish a relationship between two tables and display them on a datagrid,
edit and add new records to them.
now i need to generate a report using the parameters in the child table, and
two columns from the parent table. this is where the problem starts. when i
use two seperate connection links and extract the required data, adding it
all to the same dataset,...
| |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |