Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi my name is vishal.
For past 3 days i have breaking my head on how to change format of date field to be displayed in pdf report from c# windows forms
i have been using itextsharp to create pdf report from c# windows forms
Given below is my sql select query in c#.
C#
private void button1_Click(object sender, EventArgs e)
   {
       SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
       SqlCommand cmd = new SqlCommand("Select d.dialyserID,r.errorCode,r.dialysis_date,pn.patient_first_name,pn.patient_last_name,d.manufacturer,d.dialyzer_size,r.start_date,r.end_date,d.packed_volume,r.bundle_vol,r.disinfectant,t.Technician_first_name,t.Technician_last_name from dialyser d,patient_name pn,reprocessor r,Techniciandetail t where pn.patient_id=d.patient_id and r.dialyzer_id=d.dialyserID and t.technician_id=r.technician_id and d.deleted_status=0 and d.closed_status=0 and pn.status=1 and r.errorCode<106 and r.reprocessor_id in (Select max(r.reprocessor_id) from reprocessor r where r.dialyzer_id=d.dialyserID) order by pn.patient_first_name,pn.patient_last_name", conn);
       conn.Open();
       SqlDataReader dr;
       dr = cmd.ExecuteReader();
   }

The above query works OK.
As you can i export multiple datas from different tables into sql query given below:

I have one date field named:r.dialysis_date which is from another table named:reprocessor Given below is structure of table:reprocessor in sql server2008.
ColumnName DataType AllowNulls
reprocessor_id Int No(auto-increment primary key)
start_date datetime Yes
end_date datetime Yes
row_upd_date datetime Yes
dialysis_date date Yes
bundle_vol Int Yes
disinfectant Int Yes
technician_id Int Yes
user_id Int Yes
dialyzer_id nvarchar(20) Yes
prime_volume Int Yes

What i want is since i am exporting multiple datas from different tables from a button click and i have only 1date field name:r.dialysis_date in sql select query given above.
When i execute the query above i get date value along with 12:00:00AM which i dont want(time to be displayed at all)
example: 15-MAR-14(some date) 12:00:00AM
i want only 15-Mar-14 only to be displayed in my report not along with 15-MAR-14 12:00:00AM
What i want when i execute the sql select query above I want r.dialysis_date value to be displayed in format:dd-MMM-YYYY
I have tried every thing i know to achieve my required result in c#.
Can anyone help me to achieve my required result? Any help or guidance in solving this problem would be greatly appreciated.I hope i get a reply.
Posted
Updated 16-May-14 0:34am
v3
Comments
Richard MacCutchan 16-May-14 6:55am    
The value returned from the database is just a number that represents a date or date & time. It is your code that decides how it is displayed to the user. See the DateTime class in MSDN for details.

1 solution

change your sql like below

SQL
Select 
     d.dialyserID,
     r.errorCode,
     REPLACE(convert(varchar, r.dialysis_date, 6), ' ','-'),
     ....
 
Share this answer
 
v2
Comments
Member 10248768 19-May-14 2:08am    
First sorry for my delayed reply
Thanks DamithSL for your solution.It worked perfectly according to what i wanted.
DamithSL 19-May-14 2:30am    
You are welcome!

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