c# - The return value from a stored procedure gets the first character only in ASP.NET -


when getting return value stored procedure, returns first character,

exec sp_auto_gen_ttbdbatno 'tt', '' in sql server gets whole string, in asp.net gets first character.

how whole string value?

create proc sp_auto_gen_ttbdbatno       @prefix nvarchar(2),       @result nvarchar(8) output begin     declare @lastvalue int       -- companycode = @companycode , bankcode = @bankcode , accountcode = @accountcode      set nocount on     if @prefix = 'bd'         select @lastvalue = max(right(rtrim(isnull(batchno, '')),2)) dbo.cheque_issuerecord_secretary_review_bd isnumeric(right(rtrim(batchno),2))= 1 , len(right(rtrim(batchno),2)) = 2     else         select @lastvalue = max(right(rtrim(isnull(batchno, '')),2)) dbo.cheque_issuerecord_secretary_review_tt isnumeric(right(rtrim(batchno),2))= 1 , len(right(rtrim(batchno),2)) = 2      set nocount off     set @result = @prefix + right(rtrim(str(year(getdate()))),2)+right('0'+ltrim(rtrim(str(month(getdate())))),2) + right('0'+ltrim(rtrim(str(isnull(@lastvalue,0)+1))),2)      print @result end 

c# code:

string tauto_batch = "";  sqltransaction trans = null; using (sqlconnection connection = new sqlconnection(_connectionstring)) {     try     {         sqlcommand command = new sqlcommand("sp_auto_gen_ttbdbatno", connection);         command.commandtype = commandtype.storedprocedure;          command.parameters.add(new sqlparameter("@prefix", "tt"));         //command.parameters.add(new sqlparameter("@companycode", cheque.voucherbatchno));         //command.parameters.add(new sqlparameter("@bankcode", cheque.voucherno));         //command.parameters.add(new sqlparameter("@accountcode", cheque.voucherno));          sqlparameter resultvalue = new sqlparameter("@result", tauto_batch);         resultvalue.direction = parameterdirection.output;          command.parameters.add(resultvalue);          connection.open();         trans = connection.begintransaction();         command.transaction = trans;         command.connection = connection;          command.executenonquery();         trans.commit();          tauto_batch = command.parameters["@result"].value.tostring();          command.dispose();         trans.dispose();         connection.close();      }     catch (exception ex)     {         connection.close();         error_label.text = error_label.text + "sp_auto_gen_ttbdbatno error " + ex.message;     } } 

make sure use this:

@result nvarchar(8) output sqlparameter resultvalue = new sqlparameter("@result", sqldbtype.nvarchar, 8); 

the default length (n)varchar columns 1.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -