如何从DateTimeC# 中的结构仅将日期的时间部分插入 Sql Server 。我想以HH:mm tt(HH:MM AM/PM)格式保存时间
我尝试了以下数据类型:
timetimestampdatetimetime(7)示例查询:
SqlCommand cmd = new SqlCommand("insert into Reminder values ('" + txttitle.Text + "','" + txtdate.Text + "','" + txttime.Text + "','" + Txtmail.Text + "')", conn);
cmd.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud) 我希望用户只选择当前月份的日期我不知道应该在最小和最大日期属性中放入什么.
是否有"当月"之类的财产?
我在包含不同类型对象的对象上创建了一个数组,并检查了每个元素的类型.然后将数组转换为List并检查每个元素的类型但结果是不同的?
object[] aobj = {"",4,2.5,7,new object()};
foreach (var element in aobj)
{
Console.WriteLine("Type is Array"+element.GetType());
}
IList lsit = aobj as IList;
foreach (var element in lsit)
{
Console.WriteLine("Type is in List " + element.GetType());
}
Run Code Online (Sandbox Code Playgroud)
输出:

为什么会出现ArraySystem.Object和System.Object?有什么不同 ?
我正在尝试拆分此字符串: 2015-08-14 20:30:00
但编译器显示以下消息:
无法从String转换为Char
这是我的代码:
string date = reader["date"].ToString().Split("-").ToString();
Run Code Online (Sandbox Code Playgroud)
变量reader["date"]是一个对象,所以我必须将它转换为一个String.我想将内容分成另外三个变量,如下所示:
year: 2015
month: 08
day: 14
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
int Turns;
int Loses;
if (ProgramOn == true) {
if (MontyChoice == 1) {
goat1 = 2;
goat2 = 3;
Console.WriteLine ("1");
if (PlayerChoice == 1) {
Turns == Turns - 1;
loses == Loses + 1;
}
Run Code Online (Sandbox Code Playgroud)
我在标题中得到错误,int转换和丢失在if ProgramOn循环之外,我是否需要将它们公开?
是否可以使用您想要插入的字符串格式的变量.
public class Setting
{
public string Format { get; set; }
}
var setting = new Setting { Format = "The car is {colour}" };
var colour = "black";
var output = $"{setting.Format}";
Run Code Online (Sandbox Code Playgroud)
预期产出
"汽车是黑色的".
我正在尝试使用命名空间System.Text.RegularExpressions下的regex验证密码字段,但我收到三个错误
'无法识别的转义序列'.
当我双击错误时,它突出显示了我的表达式中的' - '字符范围,但我不知道为什么这是错误的.
//密码必须包含一个大写,一个小写和一个数字
Regex reg = new Regex("^(?=.*[!@#$%^&*()\-_=+`~\[\]{}?|])(?=.+[a-z])(?=.+[A-Z])(? =.+[0-9]).{8,50}$");
Run Code Online (Sandbox Code Playgroud) 如何确定a List<List<int>>中的项是否等于?
List<List<int>> equals = new List<List<int>>()
{
new List<int>() { 1,2 },
new List<int>() { 1,2 }
};
List<List<int>> notEquals = new List<List<int>>()
{
new List<int>() { 1,2 },
new List<int>() { 2,500}
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用代码从 Excel 读取日期
String ss = (String)w.Cells[2 + i, 4].Value2;
dRow[3] = DateTime.Parse(ss);
Run Code Online (Sandbox Code Playgroud)
代码可以工作ss = "12/11/2015"但给出错误
字符串未被识别为有效的日期时间
什么时候ss = "13/11/2015"
它给出错误,因为月份不能是 12,但它以日期作为月份。我是这么想的。相同的代码可以在其他电脑上运行。我是否需要检查我的日期时间格式或日期设置之类的内容。