Click here to Skip to main content
15,889,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am using Stored procedure for display data in gridview. Using the where condition.
My stored procedure is:

ALTER procedure [dbo].[SP_Duplications]
(
@MA_DOB varchar(20)
)
as
begin
select ma.MA_App_Code as Emp_Code,ma.MA_Title,ma.MA_First_Name +' '+ ma.MA_Last_Name as Emp_Name, ma.MA_DOB as Date_Of_Birth, ma.MA_Joining_Date,ma.MA_Expiry_Date, mc.CM_Company_Name from master_applicant as ma
inner join master_company as mc on ma.MA_company_name=mc.CM_ID where MA_DOB=@MA_DOB

end
and my actual code is:

if (rbtncheck.Checked == true)
{
dt.OpenCon();
SqlCommand cmd = new SqlCommand();
cmd.Connection = dt.SqlCon;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_Duplications";
cmd.ExecuteNonQuery();
GRD_Search_Employee.DataSource = cmd.ExecuteReader();
GRD_Search_Employee.DataBind();
dt.Dispose();

}
It is shows an exception.
Posted
Comments
Member 11221185 31-Jan-15 7:23am    
Please help me urgent
Zoltán Zörgő 31-Jan-15 7:25am    
For you maybe...

Do you understand what you read? The SP has a parameter defined. You don't supply any parameter when you call it. So, what do you expect?

Use AddWithValue[^] for example.
Add
C#
cmd.Parameters.AddWithValue("@MA_DOB", "xyz");
before calling ExecuteNonQuery().

BTW: ExecuteNonQuery and ExecuteReader after another???
 
Share this answer
 
v2
Comments
Member 11221185 31-Jan-15 8:04am    
I just want to select data from database & bind it to gridview. so why i need this code:-
cmd.Parameters.AddWithValue("@MA_DOB", "xyz");
Zoltán Zörgő 31-Jan-15 8:27am    
Beacuse the procedure is defined to require a parameter. Rewrite the procedure if you do1t need it.
As Zoltan Zorgo provided the piece of code, it will resolve your error, but you want to get this value from db then do this

1. delete the @MA_DOB as input.
2. declare @MA_DOB as a normal variable


SQL
Declare @MA_DOB varchar(20)
select @MA_DOB = <column_name> from <table_name> where <search>


write these before your operation and do whatever you want with the value of @MA_DOB
 
Share this answer
 
v2
Comments
Member 11221185 1-Feb-15 23:45pm    
Thanks My problem has been solved.Thanks For the help.
Arkadeep De 2-Feb-15 0:03am    
If your problem has been solved then accept the solution and make this solve.

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