Click here to Skip to main content
15,917,565 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i select the table data from SQL server using store procedure and load this data to my C# application that containing a GridView. It take Alos time with data but in gridview Only date is shown And when i take a print of this gridview 12:00 this time Also include in date colum in printpriview..
Colume name "EmDate" datatype "Datetime"
I want only date is print.
Please Any one Help me.
Thanks in advance

What I have tried:

Its My Store Procedure
ALTER PROCEDURE [dbo].[USP_Selec_Custtomer_Record] 
AS
BEGIN
	SELECT 
	   [CustomSr]			as 'sr'
	 , DateWork = CONVERT(date, DateWork, 103)		      
      ,[EmpolyName]			as 'Empoly Name'
      ,[EmID]				as 'Empoly ID'
      ,[CustomerName]		as 'Customer Name'
      ,[PhoneNo]			as 'Phone No '
      ,[CustomAddress]		as 'Customer Address'
      ,[CashType]			as 'Cash Type'
      ,[LumSum]				as 'LumSum Amount'
      ,[TotalToPay]			as 'Total to pay'
      ,[RemainingBalnce]	as 'Remaining Amount'
  FROM [dbo].[Customer_Records]


Its my C# Code i use Print Document Control to take Print. This line take print of Date.
e.Graphics.DrawString(CustomerDetilsdataGridView.Rows[i].Cells[1].Value.ToString(), new Font("Arial", 16), Brushes.Black, 120, ysp);
Posted
Updated 17-Mar-18 19:23pm
Comments
Bryian Tan 17-Mar-18 0:07am    
is EmDate refering to DateWork column?
Fahid Zahoor 17-Mar-18 1:42am    
Yes
Bryian Tan 17-Mar-18 1:56am    
Can the DateWork be string on the application side? if yes, try something like
DateWork = convert(VARCHAR(10), DateWork, 103)
or return a new column StrDateWork = ...

Don't convert it at all in SQL - return the whole DATETIME value, then process it in your presentation language:
decimal d = (decimal) CustomerDetilsdataGridView.Rows[i].Cells[1].Value;
e.Graphics.DrawString(d.ToString("dd/MM/yyyy"), new Font("Arial", 16), Brushes.Black, 120, ysp);
Or
decimal d = (decimal) CustomerDetilsdataGridView.Rows[i].Cells[1].Value;
e.Graphics.DrawString(d.ToString("d"), new Font("Arial", 16), Brushes.Black, 120, ysp);
which will give you the short form date fro that computer's locale.
 
Share this answer
 
v2
Comments
Fahid Zahoor 17-Mar-18 5:22am    
This error is occuer and ToString underLine By read color line
"Return a string that represent the current object. No over Load for method ToString takes 1 Arguments"
Tell me what i do next???
OriginalGriff 17-Mar-18 5:28am    
Show me exactly the code you used.
Fahid Zahoor 17-Mar-18 14:42pm    
if (NumberOfItemPrintedSoFar <= CustomerDetilsdataGridView.Rows.Count)
{

e.Graphics.DrawString(""+p, new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(23, ysp));
// e.Graphics.DrawString(CustomerDetilsdataGridView.Rows[i].Cells[0].Value.ToString(), new Font("Arial", 16), Brushes.Black, 23, ysp);
e.Graphics.DrawString(CustomerDetilsdataGridView.Rows[i].Cells[1].Value.ToString() , new Font("Arial", 16), Brushes.Black, 120, ysp);
//e.Graphics.DrawString(CustomerDetilsdataGridView.Rows[i].Cells[3].Value.ToString(), new Font("Arial", 16), Brushes.Black, 330, ysp);
e.Graphics.DrawString(CustomerDetilsdataGridView.Rows[i].Cells[4].Value.ToString(), new Font("Arial", 16), Brushes.Black, 440, ysp);
e.Graphics.DrawString(CustomerDetilsdataGridView.Rows[i].Cells[9].Value.ToString(), new Font("Arial", 16), Brushes.Black, 640, ysp);
ysp += 30;
p++;
}
OriginalGriff 17-Mar-18 5:34am    
Ah! You're using a DataGridView - answer updated.
Fahid Zahoor 17-Mar-18 10:52am    
Yes I'm Using Data GridView
CONVERT(nvarchar(10), DateWork, 103);
 
Share this answer
 
Comments
Fahid Zahoor 18-Mar-18 2:09am    
Yes I'm using this. Now Paroblem is that only Date is Shown in GridView But when i take the print 12:00 this Time is also add to all the records...

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



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