Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.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
从SQL到.Net monthCalendar.BoldDates?_.net_Sql_Datetime_Date_Monthcalendar - Fatal编程技术网

从SQL到.Net monthCalendar.BoldDates?

从SQL到.Net monthCalendar.BoldDates?,.net,sql,datetime,date,monthcalendar,.net,Sql,Datetime,Date,Monthcalendar,是否可以从SQL server中选择日期并将其用于在monthCalendar中加粗日期 要在monthCalendar中加粗日期,我使用了以下代码: DateTime[] Reserveret = new DateTime[3]; Reserveret[0] = new DateTime(2012, 04, 25); Reserveret[1] = new DateTime(2012, 04, 01); Reserveret[2]

是否可以从SQL server中选择日期并将其用于在monthCalendar中加粗日期

要在monthCalendar中加粗日期,我使用了以下代码:

        DateTime[] Reserveret = new DateTime[3];
        Reserveret[0] = new DateTime(2012, 04, 25);
        Reserveret[1] = new DateTime(2012, 04, 01);
        Reserveret[2] = new DateTime(2012, 04, 12);

        monthCalendar1.BoldedDates = Reserveret;
这将在monthCalendar1中加粗这3个日期

但我不想硬编码这些日期,而是想从我的SQL数据库中选择它们,该数据库包含如下3列:

        ID       Room           Date
        1        103            2012-04-18
        2        106            2012-04-07
        3        103            2012-04-23
        4        103            2012-04-14
        5        101            2012-04-11

例如,我的最终目标是按下103键,然后2012-04-18&2012-04-23&2012-04-14将以粗体显示在monthCalendar。但我不是阵列方面的专家,我想这里需要阵列://

试试这样的东西

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{ 
    for (int i = 0; i < Reserveret .Length; i++)
    {
        if (e.Day.Date == Reserveret ) 
        { 
            e.Cell.Font.Bold = true; 
            //e.Cell.BackColor = System.Drawing.Color.red;  //You may also try this 
        } 
     }
 } 

我给这个问题加了+1,因为我正要问同样的问题,但我找到了解决的方法,是的,他问的是可能的

这篇关于的文章帮助了我,我使用了一个示例,因为我认为在从数据库获取记录时,向动态集合添加项更容易。我更改了一些代码以匹配问题

//创建一个类并粘贴它。 公共类createsCollection { 私有静态SqlConnection getConnection { SqlConnection con=新的SqlConnection; con.ConnectionString=@Data Source=yourpname\SQLEXPRESS;初始目录=。。; 返回con; } 公共静态列表datesListstring房间 { 使用var con=new SqlConnectiongetConnection.ConnectionString { SqlDataReader恐惧者; 列表日期=新列表; var cad=从您的TBL中选择日期,其中房间=@Rn; 使用var sqlCommand=new SqlCommandcad,con { 尝试 {sqlCommand.CommandType=CommandType.Text sqlCommand.Parameters。AddWithValue@Rn房间 不公开; dReader=sqlCommand.ExecuteReader; 如果dReader.HasRows==true { 而恐惧。阅读 dates.AddDateTime.ParsedReader[Date].ToString; } 返回日期; } 捕获异常 {MessageBox.ror:+ex.Message; 返回null; } } } } } 以您的形式:

列表日期ST=新列表; 列表notNullableList=新列表; 私有无效表单\u加载对象发送方,事件参数e { datesLst=createsCollection.datesList103;//这可以更改,例如Button.Text //我们需要将可为空的DateTime列表“DatesList”转换为不可为空的DatesList //DateTime数组,以便将其传递给BoldedDates属性。 if datesLst!=null//如果数据库中有记录 { foreach DateTime?日期列表中的dtm { string str=dtm.GetValuerDefault.ToShortDateString; 日期时间值; 如果是DateTime.tryparsest,则为out val { notNullableList.Addval;//将NotNull值添加到新的泛型列表中 } } monthCalendar1.BoldedDates=notNullableList.ToArray;//加粗从db收集到月历的日期 monthCalendar1.更新; monthCalendar1.UpdateBoldedDates; } } 这是一种方法,我相信有更好的方法来实现它,但当我测试它时,这对我来说非常好


如果您想使用固定大小而不是,您可能希望首先根据指定的条件返回日期行数并将其设置为数组,也不需要返回列表,但我是根据自己的喜好这样做的。干杯。

哎哟,我看不出这个代码是怎么工作的。我正在Visual Studio中开发一个C Windows应用程序,我认为不可能在monthCalendar上使用Cell.Font.Bold。需要像MonthCalendar1一样的东西BoldedDates。。。