CREATE PROCEDURE sp_Personal
@ID int,@Name varchar(50)@Gender varchar(6),@Address varchar(75),
@Phone bigint,@Status varchar(15)
AS
BEGIN
IF @Status='Create'
BEGIN
INSERT INTO Student1(Name,Gender,Address,Phone) VALUES
(@Name,@Gender,@Address,@Phone)
END
IF @Status='Update'
BEGIN
UPDATE Student1 SET Name=@NameGender=@Gender,Address=@Address,Phone=@Phone
WHERE ID=@ID
END
END
Now my issue is want to connect to frontend usind ADO.net
}
How to call a "Create" query only using Status parameter in frontend. am using MVC4 asp.net
Now my issue is want to connect to frontend usind ADO.net
public Create(Personal pers)
{
SqlConnection con = new SqlConnection("Data Source=SamplePC;Initial Catalog=Sample;Integrated Security=True");
SqlCommand com = new SqlCommand("sp_Personal", con);
com.CommandType = CommandType.StoredProcedure;
}
How to call a "Create" query only using Status parameter in frontend. am using MVC4 asp.net
VijayPosted Aug 1, 2013, 7:08 AM
But not working Create, Update, Delete using Storedprocedure ... its working with seperate queries oly..
using above StoredProcedure --- StudentApn
.cs file is.....
Iftikar HussainPosted Aug 1, 2013, 5:38 AM
Regards,
Iftikar
VijayPosted Aug 1, 2013, 5:35 AM
VijayPosted Aug 1, 2013, 5:24 AM
.cs file is
in this i getting error like... Procedure or function 'StudentApn' expects parameter '@Name', which was not supplied. please check my code wat i did wrongly
Rosi Sreenivasa ReddyPosted Aug 1, 2013, 4:47 AM
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE proc_personal
(
@Id int=0,
@Name varchar(50)=null,
@Gender varchar(6)=null,
@PAddress varchar(75)=null,
@Phone numeric=null,
@status int=o,
@result int=null,
@errmsg varchar(500)=null
)
AS
BEGIN
if(@status=1)
begin
if not exists(select Id from personal where Name=@Name)
begin
select @Id=ISNULL(max(Id),0)+1 from personal
insert into personal(Id,Name,Gender,PAddress,Phone)Values(@Id,@Name,@Gender,@PAddress,@Phone)
set @result=1
end
end
else
begin
set @result=0
set @errmsg='Name Already Exists'
end
if(@status=2)
begin
if not exists(select Id from personal where Id<>@Id and Name=@Name)
begin
update personal set Name=@Name,Gender=@Gender,PAddress=@PAddress,Phone=@Phone where Id=@Id
set @result=1
end
end
else
begin
set @result=0
set @errmsg='Name Already Exists'
end
END
GO
aspx.cs file::
SqlConnection con = new SqlConnection("data source=WEBDEV1-PC; Initial Catalog=srinu; user Id=sa; password=pftec;");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Proc_Personal";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
if(string.IsnullorEmpty(hfId.Value)
{
cmd.parametera.Add("@status",sqlDbType.Int).Value=1;
}
else
{
cmd.Parameters.Add("@ststus",sqldbtype.Int).Value=2;
cmd.Parameters.Add("@Id",dqldbtype.Int).Value=HfId.Value;
}
}
Rosi Sreenivasa ReddyPosted Aug 1, 2013, 3:17 AM
Iftikar HussainPosted Aug 1, 2013, 2:17 AM
http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4
Regards,
Iftikar
VijayPosted Aug 1, 2013, 2:12 AM
VijayPosted Aug 1, 2013, 2:10 AM
But now i wanna use only create command oly using parameter ...like
com.CommandType=CommandType("@Status='Create');
com.Parameter.AddWithValue("@Name",Name);
com.Parameter.AddWithValue("@Gender ",GENDER);
com.Parameter.AddWithValue("@Address ",ADDRESS);
com.Parameter.AddWithValue("@Phone ",Phone);
In that time i want access oly create query
I getting error... plz understand my question
Iftikar HussainPosted Aug 1, 2013, 2:03 AM
Please refer the below link for all different type of functionality including Create
Regards,
Iftikar
Posted Aug 1, 2013, 2:02 AM
SqlConnection con = new SqlConnection("Data Source=SamplePC;Initial Catalog=Sample;Integrated Security=True");
SqlCommand com = new SqlCommand("sp_Personal", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameter.AddWithValue("@ID",IDVALUE);
com.Parameter.AddWithValue("@Gender ",GENDER);
com.Parameter.AddWithValue("@Address ",ADDRESS);
com.Parameter.AddWithValue("@Phone ",Phone);
com.Parameter.AddWithValue("@Status",STATUS);
int result=com.ExecuteNonQuery();