Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c asp.net如何在sql数据库上获取月和日_C#_Asp.net_Sql_Repeater - Fatal编程技术网

C# c asp.net如何在sql数据库上获取月和日

C# c asp.net如何在sql数据库上获取月和日,c#,asp.net,sql,repeater,C#,Asp.net,Sql,Repeater,我只想在SQL数据库中获取月份和日期的日期,并将其绑定到repeater中: 正面: <asp:Repeater ID="rep_content" runat="server"> <ItemTemplate> <div class="date"> <p><%# Eval("BLG_DATE") %> of <span><%#Eval("BLG_DATE") %></span> </div>

我只想在SQL数据库中获取月份和日期的日期,并将其绑定到repeater中:

正面:

<asp:Repeater ID="rep_content" runat="server">
<ItemTemplate>
<div class="date">
<p><%# Eval("BLG_DATE") %> of <span><%#Eval("BLG_DATE") %></span>
</div>
</ItemTemplate>
</repeater>
BLG表格:

BLG_ID,ACC_ID,BLG_TITLE,BLG_DES,BLG_DATE,BLG_IMG    
输出应为:

23 of JAN
使用DatePart获取日期和月份

 daString = "SELECT datepart (dd, BLG_DATE) as DDay,datepart (mm, BLG_DATE) as DMonth
  FROM [BLG] INNER JOIN [ACC] ON [BLG].ACC_ID=[ACC].ACC_ID 
    WHERE [BLG].ACC_ID='" + userID + "'";
 SqlDataAdapter da = new SqlDataAdapter(daString, conn);
 DataTable dt = new DataTable();
 da.Fill(dt);    
 rep_content.DataSource = dt;
 rep_content.DataBind();


 <p><%# Eval("DDay") %> of <span><%#Eval("DMonth") %></span>
这样做,

<asp:Repeater ID="rep_content" runat="server">
<ItemTemplate>
<div class="date">
<p><%# Eval("DDay") %> of <span><%#System.Globalization.DateTimeFormatInfo.InvariantInfo.GetAbbreviatedMonthName(Convert.ToInt32(Eval("DMonth")))%></span>
</div>
</ItemTemplate>
</repeater>

我怎样才能用它来做广告呢?你能给我举个例子吗?谢谢!它可以工作,但我在D月有一个问题,它的显示编号不是JANTry这个替换mm,BLG_日期到CastDate部分mm,BLG_日期作为字符3谢谢你的答案CastDate部分mm,BLG_日期作为字符3不起作用,我把它改为CastDate名称月份,BLG_日期作为字符3。谢谢。您应该使用参数化查询。当SQL查询是通过字符串连接构建的时,您就容易受到SQL注入攻击。我不知道如何使用SQL参数。除息的
<asp:Repeater ID="rep_content" runat="server">
<ItemTemplate>
<div class="date">
<p><%# Eval("DDay") %> of <span><%#System.Globalization.DateTimeFormatInfo.InvariantInfo.GetAbbreviatedMonthName(Convert.ToInt32(Eval("DMonth")))%></span>
</div>
</ItemTemplate>
</repeater>