[英]Ado.net, DateTime in SqlCommand
I have DataSet "_cinemaZone" with DataTable "SessionsCinema", this DataTable has DataColumn "sessionDateTime" with DataType - "typeof(System.DateTime)". 我有数据集“ _cinemaZone”和数据表“ SessionsCinema”,此数据表有数据列“ sessionDateTime”,数据类型为“ typeof(System.DateTime)”。
Help me, please, to use "sessionDateTime" field in SqlCommand. 请帮助我,以使用SqlCommand中的“ sessionDateTime”字段。
My wrong tries: 我的错误尝试:
//first
commandSql.Parameters.Add("@sessionDateTime", SqlDbType.DateTime, sizeof(DateTime), "sessionDateTime");
//second
commandSql.Parameters.Add("@sessionDateTime", SqlDbType.DateTime);
commandSql.Parameters["@sessionDateTime"].Value = sessionDateTime;
//third
commandSql.Parameters.Add("@sessionDateTime", SqlDbType.DateTime);
commandSql.Parameters["@sessionDateTime"].Value = Convert.ToDateTime(_cinemaZone.Tables["SessionsCinema"].Columns["sessionDateTime"]);
foreach (DataRow row in _cinameZone.Tables["SessionsCinema"].Rows)
{
var sqlParameter = new SqlParameter("@paramName", SqlDbType.DateTime)
{
Value = Convert.ToDateTime(row["sessionDateTime"].Value);
}
cmd.Parameters.Add(sqlParameter);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.