Hi,
How will the stored procedure be used in web service application to insert record into database table. plz, explain with example.
Thanks.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pravin MoreRank #1,419 · 1.2K reputationPosted Dec 18, 2011, 7:21 PM EST
here is complete code on it...........
web Service code...........
[OperationContract]
public string InsertRow(string empname,string designation)
{
SqlConnection dbConn = null;
dbConn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["insightconnection"].ToString());
SqlCommand cmd;
SqlDataReader dr;
dbcon.Open();
spcmd = new SqlCommand("SP_InsertRow", spcon);
spcmd.CommandType = CommandType.StoredProcedure;
spcmd.Parameters.Add(new SqlParameter("@EMPName", empname));
spcmd.Parameters.Add(new SqlParameter("@DEsignation", designation));
dr = cmd.ExecuteReader();
return "inserted......!!! ";
}
Stored Procedure code..............
create PROCEDURE [dbo].[SP_InsertRow]
@EMPName varchar(max),
@DEsignation varchar(max)
AS
BEGIN
SET NOCOUNT ON;
insert into EMPDetails values(@EMPName,@DEsignation)
End
Thanks,
Pravin.
Alok PandeyRank #271 · 9.3K reputationPosted Dec 18, 2011, 8:46 PM EST
Pravin MoreRank #1,419 · 1.2K reputationPosted Dec 18, 2011, 8:54 PM EST
asif iqbal3 reputationPosted Aug 24, 2012, 4:53 AM EDT
Hi Pravin,
As per your given code suppose I have webmethods for Delete and Update too,
And I need to consume them(WebMethods) in my web application where I also have to handle Transaction,
Can you provide with example of codes while consuming transaction should also gets handle.
Since I cannot use connection.BeginTransaction in my Consuming application becoz connection part is run inside webmethod
e.g.
/Application Consuming Webmethod
try
{
//Here I need to handle Transaction if any error occurred in
//middle of sth the transaction should get rolled back
service1.InsertRow(param1, param2);
service1.DeleteRow(param3, param4);
service1.UpdateRow(param5, param6);
}
Catch
{
}
web Service code...........
[OperationContract]
public string InsertRow(string empname,string designation)
{
SqlConnection dbConn = null;
dbConn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["insightconnection"].ToString());
SqlCommand cmd;
SqlDataReader dr;
dbcon.Open();
spcmd = new SqlCommand("SP_InsertRow", spcon);
spcmd.CommandType = CommandType.StoredProcedure;
spcmd.Parameters.Add(new SqlParameter("@EMPName", empname));
spcmd.Parameters.Add(new SqlParameter("@DEsignation", designation));
dr = cmd.ExecuteReader();
return "inserted......!!! ";
}
Stored Procedure code..............
create PROCEDURE [dbo].[SP_InsertRow]
@EMPName varchar(max),
@DEsignation varchar(max)
AS
BEGIN
SET NOCOUNT ON;
insert into EMPDetails values(@EMPName,@DEsignation)
End