如何使用sql server2008从c#windows窗体中更改sql select查询中的日期字段值的格式 [英] how to change format of date field value in sql select query from c# windows forms with sql server2008
问题描述
你好我的名字是vishal。
在过去的3天里,我已经打破了如何改变日期字段的格式,以便在c#窗体中显示pdf报告
i一直使用itextsharp从c#windows窗口创建pdf报告
下面给出的是我在c#中的sql select查询。
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#.
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();
}
上面的查询工作正常。
我可以将不同表中的多个数据导出到sql中查询如下:
我有一个名为: r.dialysis_date 的日期字段来自另一个名为 reprocessor 的表b>下面给出了表结构: reprocessor 在sql server2008中。
ColumnName DataType AllowNulls
reprocessor_id Int否(自动增加主键)
start_date datetime是
end_date datetime是
row_upd_date datetime是
dialysis_date date是
bundle_vol Int Yes
消毒剂Int Yes
technician_id Int Yes
user_id Int Yes
dialyzer_id nvarchar(20)是
prime_volume Int Yes
我想要的是因为我从按钮单击导出来自不同表的多个数据,并且我在上面给出的sql select查询中只有1date字段名: r.dialysis_date 。 br />
当我执行上面的查询时,我得到日期值以及上午12:00:00,我不想要(时间显示)
示例:15 -MAR-14(某个日期)12:00:00 AM
我只希望15-Mar-14 显示在我的报告中,而不是15-MAR-14 12:00:00 AM
当我执行上面的sql select查询时,我想要 r。 dialysis_date 以格式显示的值: dd-MMM-YYY
我已经尝试了所有我知道的交流在c#中获得我所需的结果。
有谁能帮助我达到我要求的结果?任何帮助或指导解决这个问题将不胜感激。我希望我得到答复。
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.
推荐答案
改变你的sql如下
change your sql like below
Select
d.dialyserID,
r.errorCode,
REPLACE(convert(varchar, r.dialysis_date, 6), ' ','-'),
....
这篇关于如何使用sql server2008从c#windows窗体中更改sql select查询中的日期字段值的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!