将数据类型nvarchar转换为日期时出错 [英] Error converting data type nvarchar to date

查看:168
本文介绍了将数据类型nvarchar转换为日期时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友

我想用Store Procedure填充DataSet。但是当我运行我的项目时出现此错误:

将数据类型nvarchar转换为日期时出错。

1-我必须

Hi friends
I want to fill DataSet with Store Procedure.but when i have run my project i get this error:
Error converting data type nvarchar to date.
1- Do i have to

SqlDataAdapter adp = new SqlDataAdapter();
           adp.SelectCommand = new SqlCommand();
           adp.SelectCommand.Connection = con;
           adp.SelectCommand.CommandText = "Report";

           adp.SelectCommand.CommandType = CommandType.StoredProcedure;
           DataSet set = new DataSet();
           DataTable dtbl = new DataTable("DataTable1");


           adp.SelectCommand.Parameters.AddWithValue("@clrk_Name", txtNameReport.Text);
           adp.SelectCommand.Parameters.AddWithValue("@clrk_Family",txtFamilyReport.Text);
           adp.SelectCommand.Parameters.AddWithValue("@clrk_MelliCode",txtMelliCodeReport.Text);
           adp.SelectCommand.Parameters.AddWithValue("@AzTarikh",txtMelliCodeReport.Text);
           adp.SelectCommand.Parameters.AddWithValue("@Ela", txtElaReport.Text);
           adp.Fill(set, "DataTable1");// this line have got error
           ReportDataSource  source = new ReportDataSource ("datatable1",dtbl );
           reportViewer1.Visible = true;

           reportViewer1.LocalReport.ReportPath = "report1.rdlc";
           reportViewer1.LocalReport.DataSources.Clear();
           reportViewer1.LocalReport.DataSources.Add(source);
           reportViewer1.LocalReport.Refresh();





商店程序



STORE PROCEDURE

USE [ClerksEvaluation]
GO
/****** Object:  StoredProcedure [dbo].[Report]    Script Date: 02/03/2013 09:24:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[Report]

@clrk_Name	Nvarchar(50),
@clrk_Family		Nvarchar(60),
@clrk_MelliCode		Char(10),
@AzTarikh			Date,
@Ela				Date

AS

Declare @id int
select @id = clrk_Id from Clerk 
where clrk_Name = @clrk_Name and clrk_Family = @clrk_Family and clrk_MelliCode = @clrk_MelliCode

select  clrk_Name,clrk_Family,clrk_MelliCode,clrk_FatherName, epcnt_Name, clrke_Percent, clrke_Tozihat, clrke_Date, clrke_Hafteh  
from ClerkEvaluation
inner join Clerk on Clerk.clrk_Id = @id
inner join EvaluationPercent on ClerkEvaluation.epcnt_Id = EvaluationPercent.epcnt_Id
where clrke_Date Between @AzTarikh and @Ela

//我从这一行得到日期但是数据集不能填充数据类型的日期。我不知道我在哪里应该使用转换?

如何在数据集中添加日期?



添加的代码块[/编辑]

//i get date from this line but dataset can''t fill data kind of date.I don''t know where i should use convert?
how can i put a date into dataset?

Code blocks added[/Edit]

推荐答案

尝试使用SqlDateTime类型。

Try to use SqlDateTime type.
System.Data.SqlTypes.SqlDateTime m_dtm = System.Data.SqlTypes.SqlDateTime.Parse(txtMelliCodeReport.Text);
adp.SelectCommand.Parameters.AddWithValue("@clrk_MelliCode", m_dtm);

System.Data.SqlTypes.SqlDateTime az_dtm = System.Data.SqlTypes.SqlDateTime.Parse(txtMelliCodeReport.Text);
adp.SelectCommand.Parameters.AddWithValue("@AzTarikh", az_dtm);


这篇关于将数据类型nvarchar转换为日期时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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