如何从asp.net中的sql server到dropdownlist获取smalldatetime [英] How to get smalldatetime from sql server to dropdownlist in asp.net
问题描述
亲爱的先生,
我的程序获得了像这种格式的smalldatetime记录
2013-04-16 00:00:00
如何使用asp.net和C在ShortDateString中显示这个日期#
con.Open() ;
//字符串caseTtl_qry =从tblLegealCases中选择distinct(Case_Title);
SqlCommand cmd = new SqlCommand(GetSingleEntryDates,con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(@ Empid,Session [Empid]);
DataTable dt = new DataTable();
SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
sqlDa.Fill(dt);
DropDownSingleEntryDate.DataTextField =attendance_date;
DropDownSingleEntryDate.DataSource = dt;
DropDownSingleEntryDate.DataBind();
con.Close();
谢谢
vilas
Dear Sir ,
My procedure get the record of smalldatetime like this format
2013-04-16 00:00:00
how to show this dates in ShortDateString using asp.net and C#
con.Open();
// string caseTtl_qry = "select distinct( Case_Title) from tblLegealCases";
SqlCommand cmd = new SqlCommand("GetSingleEntryDates", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Empid", Session["Empid"]);
DataTable dt = new DataTable();
SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
sqlDa.Fill(dt);
DropDownSingleEntryDate.DataTextField = "attendance_date";
DropDownSingleEntryDate.DataSource = dt;
DropDownSingleEntryDate.DataBind();
con.Close();
thanks
vilas
推荐答案
我使用DataTextFormatString来形成下拉列表的字符串
con.Open();
// string caseTtl_qry =从tblLegealCases中选择distinct(Case_Title);
SqlCommand cmd = new SqlCommand(GetSingleEntryDates,con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(@ Empid,Session [Empid]);
DataTable dt = new DataTable();
SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
sqlDa.Fill(dt);
DropDownSingleEntryDate.DataTextField = attendance_date;
DropDownSingleEntryDate.DataTextFormatString = string.Format({0:d / M / yyyy},DateTime.Now.ToShortDateString());
Dro pDownSingleEntryDate.DataSource = dt;
DropDownSingleEntryDate.DataBind();
con.Close();
和输出在下拉列表中
24/04/2013
谢谢
vilas
I have use DataTextFormatString for formating string of dropdownlist
con.Open();
// string caseTtl_qry = "select distinct( Case_Title) from tblLegealCases";
SqlCommand cmd = new SqlCommand("GetSingleEntryDates", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Empid", Session["Empid"]);
DataTable dt = new DataTable();
SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
sqlDa.Fill(dt);
DropDownSingleEntryDate.DataTextField = "attendance_date";
DropDownSingleEntryDate.DataTextFormatString = string.Format("{0:d/M/yyyy}", DateTime.Now.ToShortDateString());
DropDownSingleEntryDate.DataSource = dt;
DropDownSingleEntryDate.DataBind();
con.Close();
and output is in dropdownlist as
24/04/2013
thanks
vilas
我使用DataTextFormatString来形成下拉列表的字符串
con.Open( );
// string caseTtl_qry =从tblLegealCases中选择distinct(Case_Title);
SqlCommand cmd = new SqlCommand(GetSingleEntryDates,con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(@ Empid,Session [Empid]);
DataTable dt = new DataTable();
SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
sqlDa.Fill(dt);
DropDownSingleEntryDate.DataTextField =attendance_d吃了;;
DropDownSingleEntryDate.DataTextFormatString ={0:d / M / yyyy};
DropDownSingleEntryDate.DataSource = dt;
DropDownSingleEntryDate.DataBind();
con.Close();
和输出在下拉列表中
24/04/2013
谢谢
vilas
I have use DataTextFormatString for formating string of dropdownlist
con.Open();
// string caseTtl_qry = "select distinct( Case_Title) from tblLegealCases";
SqlCommand cmd = new SqlCommand("GetSingleEntryDates", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Empid", Session["Empid"]);
DataTable dt = new DataTable();
SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
sqlDa.Fill(dt);
DropDownSingleEntryDate.DataTextField = "attendance_date";
DropDownSingleEntryDate.DataTextFormatString ="{0:d/M/yyyy}";
DropDownSingleEntryDate.DataSource = dt;
DropDownSingleEntryDate.DataBind();
con.Close();
and output is in dropdownlist as
24/04/2013
thanks
vilas
这篇关于如何从asp.net中的sql server到dropdownlist获取smalldatetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!