无法将参数值从DateTime转换为Byte [] [英] Failed to convert parameter value from a DateTime to a Byte[]

查看:195
本文介绍了无法将参数值从DateTime转换为Byte []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将参数从DateTime转换为Byte []。
这个想法是通过控件输入的两个指定日期之间显示数据,并显示在GridView上,并使用存储过程访问数据。我不明白错误,但我猜测所有的数据都放在一个数组中并传递给存储过程:

I'm getting error converting parameters from DateTime to Byte[]. The idea is to show data between 2 specified dates that are entered via controls and displayed on GridView, and using a stored procedure to access data. I don't understand the error, but I'm guessing that all the data is put in an Array and passed on to stored procedure:

string sDateBegin = Request.Form["fromDate"];
DateTime dtDateBegin = Convert.ToDateTime(sDateBegin);
SqlParameter prmDateBegin = new SqlParameter("datebegin", SqlDbType.Timestamp);
prmDateBegin.Value = dtDateBegin;
cmdProc.Parameters.Add(prmDateBegin);

//same code for DateEnd

// data table
DataTable dataTable = new DataTable();

AGridView.DataSourceID = null;

// data adapter
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdProc);
AGridView.DataSource = dataTable;

//fill datatable
dataAdapter.Fill(dataTable);


推荐答案

您将SqlParameter定义为Timestamp数据类型(它是一个字节数组),而不是一个DateTime。鉴于您代表日期范围,您应该将参数数据类型更改为DateTime。

You've defined the SqlParameter as a Timestamp data type (which is a byte array) rather than a DateTime. Given you're representing a date range it sounds like you should change the parameter data type to DateTime.

这篇关于无法将参数值从DateTime转换为Byte []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆