Click here to Skip to main content
15,891,909 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
C#
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
SQL
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?

[Edit]Code blocks added[/Edit]
Posted
Updated 3-Feb-13 4:41am
v4
Comments
Sergey Alexandrovich Kryukov 3-Feb-13 22:35pm    
How come you use nvarchar instead of time in first place?
—SA

1 solution

Try to use SqlDateTime type.
C#
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);
 
Share this answer
 
Comments
Elham.Deljooei 4-Feb-13 0:48am    
HiThx for your solution.
skydger 4-Feb-13 1:07am    
Hello! You're welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900