[英]SQLException on ADO.Net SqlCommand.EndExecuteReader
[英]Ado.net, DateTime in SqlCommand
我有數據集“ _cinemaZone”和數據表“ SessionsCinema”,此數據表有數據列“ sessionDateTime”,數據類型為“ typeof(System.DateTime)”。
請幫助我,以使用SqlCommand中的“ sessionDateTime”字段。
我的錯誤嘗試:
//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.