set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author:
-- Create date:
-- Description:
-- =============================================
ALTER PROCEDURE [dbo].[ASP_CountryMaster]
@CountryID int=NULL,
@CountryName varchar(50)=NULL,
@OtherFlag tinyint=NULL,
@Operation varchar(50)=null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
if(@Operation='selectall')
begin
select * from CountryMaster where OtherFlag=1
end
if(@Operation='selectallother')
begin
select * from CountryMaster where OtherFlag=0
end
if(@Operation='insert')
begin
insert into CountryMaster
(
CountryName,
OtherFlag
)
values
(
@CountryName,
@OtherFlag
)
end
if(@Operation='selectbyid')
begin
select * from CountryMaster where CountryID=@CountryID
end
if(@Operation='update')
begin
update CountryMaster set
CountryName=@CountryName where CountryID=@CountryID
end
if(@Operation='updateotherflag')
begin
update CountryMaster set
OtherFlag=@OtherFlag where CountryID=@CountryID
end
if(@Operation='delete')
begin
Delete from CountryMaster where CountryID=@CountryID
end
select @@Identity
END
.......End Of Store procedure.......
...Strat how to call store procdure without specifying all the field....
1) to Get value by ID
AppDB ObjDB = new AppDB();
SqlDataAdapter DA = new SqlDataAdapter("ASP_OrderDealer", ObjDB.con);
DA.SelectCommand.CommandType = CommandType.StoredProcedure;
DA.SelectCommand.Parameters.AddWithValue("@UserID", objOrderDealer.UserID);
DA.SelectCommand.Parameters.AddWithValue("@Operation", "selectbyuserid");
DataSet ds = new DataSet();
ObjDB.OpenDB();
DA.Fill(ds);
ObjDB.CloseDB();
if (ds.Tables[0].Rows.Count > 0)
{
return ds;
}
else
{
return null;
}
2) For inserting record..........
AppDB ObjDB = new AppDB();
SqlCommand SC = new SqlCommand("ASP_OrderDealer", ObjDB.con);
SC.CommandType = CommandType.StoredProcedure;
SC.Parameters.AddWithValue("@UserID", objOrderDealer.UserID);
SC.Parameters.AddWithValue("@GrossTotal", objOrderDealer.GrossTotal);
SC.Parameters.AddWithValue("@Remarks", objOrderDealer.Remarks);
SC.Parameters.AddWithValue("@Specification", objOrderDealer.Specification);
SC.Parameters.AddWithValue("@Requirement", objOrderDealer.Requirement);
SC.Parameters.AddWithValue("@Transport", objOrderDealer.Transport);
SC.Parameters.AddWithValue("@Paymentmode", objOrderDealer.Paymentmode);
SC.Parameters.AddWithValue("@Status", objOrderDealer.Status);
SC.Parameters.AddWithValue("@Operation", "insert");
ObjDB.OpenDB();
Object objs = SC.ExecuteScalar();
if (objs != null)
{
newOrderDealer = Convert.ToInt32(objs);
}
ObjDB.CloseDB();

