Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

I make program to select data every day automatically by timer every second in c#

In sql server 2005 i write the following query

SQL
ALTER proc [dbo].[JeddahSalesAll]
as
SELECT     ROW_NUMBER() OVER (ORDER BY dbo.[Jeddah-Live$Sales Header].No_) AS [S.N], dbo.[Jeddah-Live$Sales Line].[Document No_] AS 'OrderNo', 
dbo.[Jeddah-Live$Sales Header].[Bill-to Name] AS 'CustomerNo', dbo.[Jeddah-Live$Sales Line].Area AS 'Shippment Type', dbo.[Jeddah-Live$Sales Line].Description AS 'Description', 
dbo.[Jeddah-Live$Sales Header].[Pump No_] AS 'PumpNo', CAST(ROUND(dbo.[Jeddah-Live$Sales Line].Quantity, 0, 1) AS int) AS 'Required Qunatity', 
CAST(ROUND(dbo.[Jeddah-Live$Sales Line].[Quantity Shipped], 0, 1) AS int) AS 'Shipped Quantity', CAST(ROUND(dbo.[Jeddah-Live$Sales Line].[Outstanding Quantity], 0, 
1) AS int) AS 'Outstanding Qunatity '
FROM         dbo.[Jeddah-Live$Sales Header] INNER JOIN
dbo.[Jeddah-Live$Sales Line] ON dbo.[Jeddah-Live$Sales Header].No_ = dbo.[Jeddah-Live$Sales Line].[Document No_] AND 
dbo.[Jeddah-Live$Sales Header].[Sell-to Customer No_] = dbo.[Jeddah-Live$Sales Line].[Sell-to Customer No_]  
WHERE DATEDIFF(d,dbo.[Jeddah-Live$Sales Line].[Shipment Date],GETDATE()) = 0

IN C# WINDOWS FORM VISUAL STUDIO 2008 IN TIMER TICK EVENT INTERVAL IS 1000MILISECOND(EVERY SECOND)

C#
Sales.SalesClass SalesClass1 = new Sales.SalesClass();
DataTable dt = SalesClass1.ShowSalesData("Data Source=192.168.1.5;Initial Catalog=Altawi-last06-01-2015;User ID=admin;Password=123");
dataGridView1.DataSource = dt;
dataGridView1[0, dataGridView1.Rows.Count - 1].Value = "Total Sum";
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Style.BackColor = Color.Yellow;
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Style.ForeColor = Color.Red;
dataGridView1.Refresh();
CLASS CODE AS FOLLOWING

C#
class SalesClass
{
public DataTable ShowSalesData(string ConnectionString)
{
SqlConnection con = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "JeddahSalesAll";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
return dt;
}

code above work success no any problem

only problem the order start 8 pm in date(31/03/2015) and finish 7 am in date(01/04/2015)

at next day

what i do to show the orders done from 12 am to 7 am to show

if you have solution or suggestion to solve problem help me if possible

thanks
Posted
Updated 31-Mar-15 4:34am
v2
Comments
ZurdoDev 31-Mar-15 10:39am    
I don't see any code that checks for time. I think your data may be off then or there is something else.

1 solution

Try playing with the datediff in hours instead of days like the following:
SQL
WHERE DATEDIFF(hh,dbo.[Jeddah-Live$Sales Line].[Shipment Date],GETDATE()) <12 -- or >12
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900