本文介绍了发送参数到存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在Sql server中有存储过程,它有很多字段,其中一些在参数列表中初始化。那么我需要从asp.net传递这些参数值还是绕过它们?看下面我的代码来了解我的意思。 商店程序: 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 结束 CATCH 发送电子邮件的C#代码: public class MessageQueueBizz { public string ToMobileNo { get ; set ; } public string 消息{ get ; set ; } public MessageQueueBizz( string ToMobileNo,字符串消息) { 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( @消息,MessageQueueBizz.Message); cmd.Parameters.Add(pMessage); int result = Convert.ToInt32(cmd.ExecuteNonQuery()); DataBaseConnectionSMSDB.CloseConnection(); 返回结果; } 解决方案 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)ASBEGIN 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 TRANSACTIONEND TRYBEGIN CATCH ROLLBACK TRANSACTIONEND CATCHC# 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; } 解决方案 这篇关于发送参数到存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-22 13:57