I have store procedure in Sql server, which has many fields and some of them are initialized in parameters list. So do i need to pass those parameters a value from asp.net or bypass them ? see my code below to get my meaning.
Store Procedure:
ALTER PROCEDURE [dbo].[ADD_SMS_InQueue]
(
@ToMobNo varchar(15),
@Message nvarchar(2000),
@encoding_Type int=0,
@IsAlertSMS bit=0,
@priority int=2,
@SendByUser int=1,
@MessageType tinyint=0
)
AS
BEGIN TRY
BEGIN TRANSACTION
INSERT INTO MessageQueue ([QueueDateTime] ,Client_ID,ToMobileNo,
[Message],LongMessageType_ID,EncodingType_ID,AlertMessage,LocalSMS,Priority_ID,Attempts,TotalAttempts,Status_ID,SendByUser,MessageType)
values (GETDATE(),1,@ToMobNo,@Message,3,@encoding_Type,@IsAlertSMS,1,@priority,0,0,1,@SendByUser,@MessageType)
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH
C# code for sending vales:
public class MessageQueueBizz
{
public string ToMobileNo { get; set; }
public string Message { get; set; }
public MessageQueueBizz(string ToMobileNo, string Message)
{
this.ToMobileNo = ToMobileNo;
this.Message = Message;
}
}
public class ManageQueueBizz
{
public int Insert(MessageQueueBizz MessageQueueBizz)
{
SqlCommand cmd = new SqlCommand("ADD_SMS_InQueue", DataBaseConnectionSMSDB.OpenConnection());
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter pToMobileNo = new SqlParameter("@ToMobNo", MessageQueueBizz.ToMobileNo);
cmd.Parameters.Add(pToMobileNo);
SqlParameter pMessage = new SqlParameter("@Message", MessageQueueBizz.Message);
cmd.Parameters.Add(pMessage);
int result = Convert.ToInt32(cmd.ExecuteNonQuery());
DataBaseConnectionSMSDB.CloseConnection();
return result;
}