A
AnkitSoni29
Guest
I am Using ASP.Net Web Service and Stored Procedure for saving data into SQL Server
Here is the Web Service:-
[WebMethod]
public void PostBusiness(string BusinessName, string FirstName, string LastName, string Address, string City, string State, string Country, string EmailID, string ContactNumber, string AppVersion, string UserName, string AdminPassword, string IPAddress, string BusinesssLogo)
{
Int64 BID = 0;
try
{
using (SqlConnection sqlcon = new SqlConnection(GetConnectionString()))
{
SqlCommand sqlcom = new SqlCommand("InsertBusiness", sqlcon);
sqlcom.CommandType = CommandType.StoredProcedure;
sqlcom.Parameters.AddWithValue("@BusinessName", BusinessName);
sqlcom.Parameters.AddWithValue("@FirstName", FirstName);
sqlcom.Parameters.AddWithValue("@LastName", LastName);
sqlcom.Parameters.AddWithValue("@Image", Image);
sqlcon.Open();
BID = (Int64)sqlcom.ExecuteScalar();
sqlcon.Close();
}
JavaScriptSerializer a = new JavaScriptSerializer();
var varResult = new { result = "Ok", AddedBusinessID = BID };
Context.Response.Write(a.Serialize(varResult));
}
catch (Exception ex)
{
JavaScriptSerializer a = new JavaScriptSerializer();
var varResult = new { result = "Error", Error = ex };
Context.Response.Write(a.Serialize(varResult));
}
}
Stored Procedure:-
ALTER PROCEDURE [dbo].[InsertBusiness]
-- Add the parameters for the stored procedure here
@BusinessName NVARCHAR(255),
@FirstName NVARCHAR(150),
@LastName NVARCHAR(150),
@Address NVARCHAR(255),
@City NVARCHAR(150),
@State NVARCHAR(150),
@Country NVARCHAR(150),
@EmailID NVARCHAR(150),
@ContactNumber NVARCHAR(20),
@AppVersion NVARCHAR(50),
@UserName NVARCHAR(150),
@AdminPassword NVARCHAR(50),
@IPAddress NVARCHAR(150),
@BusinessLogo image
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO dbo.Business (BusinessName,FirstName,LastName,Address,City,State,Country,EmailID,ContactNumber,AppDownloaded,AppVersion,UserName,AdminPassword,CreatedDate,IPAddress,BusinessLogo)
VALUES (@BusinessName,@FirstName,@LastName,@Address,@City,@State,@Country,@EmailID,@ContactNumber,GETDATE(),@AppVersion,@UserName,@AdminPassword,GETDATE(),@IPAddress,@BusinessLogo)
SELECT CAST(scope_identity() AS BIGINT)
END
Please let me know how to add image through web service i am newbie in C#.
Continue reading...
Here is the Web Service:-
[WebMethod]
public void PostBusiness(string BusinessName, string FirstName, string LastName, string Address, string City, string State, string Country, string EmailID, string ContactNumber, string AppVersion, string UserName, string AdminPassword, string IPAddress, string BusinesssLogo)
{
Int64 BID = 0;
try
{
using (SqlConnection sqlcon = new SqlConnection(GetConnectionString()))
{
SqlCommand sqlcom = new SqlCommand("InsertBusiness", sqlcon);
sqlcom.CommandType = CommandType.StoredProcedure;
sqlcom.Parameters.AddWithValue("@BusinessName", BusinessName);
sqlcom.Parameters.AddWithValue("@FirstName", FirstName);
sqlcom.Parameters.AddWithValue("@LastName", LastName);
sqlcom.Parameters.AddWithValue("@Image", Image);
sqlcon.Open();
BID = (Int64)sqlcom.ExecuteScalar();
sqlcon.Close();
}
JavaScriptSerializer a = new JavaScriptSerializer();
var varResult = new { result = "Ok", AddedBusinessID = BID };
Context.Response.Write(a.Serialize(varResult));
}
catch (Exception ex)
{
JavaScriptSerializer a = new JavaScriptSerializer();
var varResult = new { result = "Error", Error = ex };
Context.Response.Write(a.Serialize(varResult));
}
}
Stored Procedure:-
ALTER PROCEDURE [dbo].[InsertBusiness]
-- Add the parameters for the stored procedure here
@BusinessName NVARCHAR(255),
@FirstName NVARCHAR(150),
@LastName NVARCHAR(150),
@Address NVARCHAR(255),
@City NVARCHAR(150),
@State NVARCHAR(150),
@Country NVARCHAR(150),
@EmailID NVARCHAR(150),
@ContactNumber NVARCHAR(20),
@AppVersion NVARCHAR(50),
@UserName NVARCHAR(150),
@AdminPassword NVARCHAR(50),
@IPAddress NVARCHAR(150),
@BusinessLogo image
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO dbo.Business (BusinessName,FirstName,LastName,Address,City,State,Country,EmailID,ContactNumber,AppDownloaded,AppVersion,UserName,AdminPassword,CreatedDate,IPAddress,BusinessLogo)
VALUES (@BusinessName,@FirstName,@LastName,@Address,@City,@State,@Country,@EmailID,@ContactNumber,GETDATE(),@AppVersion,@UserName,@AdminPassword,GETDATE(),@IPAddress,@BusinessLogo)
SELECT CAST(scope_identity() AS BIGINT)
END
Please let me know how to add image through web service i am newbie in C#.
Continue reading...