c# 4.0 - how to get the auto generated values from sql using c#? -
i have stored procedure below..
create procedure [dbo].[spmyspdetails] @id varchar(6), @name varchar(50), @limit money, @status varchar(1), @accounts smallint begin if(len(isnull(@strdebtorid, '')) = 0) begin while 0 = 0 begin set @id = '9' + dbo.fngeneraterandomcode(5, '0123456789') if not exists (select 1 mytbl (nolock) s_id = @id) begin insert mytbl (d_id, d_name, d_limit, d_status, d_accounts, d_dtmstamp, d_balance) values (@id, @name, @limit, @status, @accounts, getdate(), @limit) break end
i have c# sharp code call sp this...
try { string id = ""; if (hddid.value.tostring() != "") { id = hddid.value.tostring(); } objdb.blnparamclear(); objdb.blnparamadd(parameterdirection.input, "@id", sqldbtype.varchar, 6, id.tostring()); objdb.blnparamadd(parameterdirection.input, "@name", sqldbtype.varchar, 50, txtname.value.tostring()); objdb.blnparamadd(parameterdirection.input, "@limit", sqldbtype.money, 8, decimal.parse(txtlimit.value.tostring())); objdb.blnparamadd(parameterdirection.input, "@status", sqldbtype.varchar, 1, cbostatus.value); objdb.blnparamadd(parameterdirection.input, "@intmaxaccounts", sqldbtype.smallint, 4, txtaccnts.value.tostring()); blnresult = (objdb.lngexecutesp("spmyspdetails") == 0); }
now want catch auto generated(random) id in c# reference. tried unable catch.. there way catch same id generated sp in sql.suggest me something...
use @id output variable.
@id varchar(6) output
then set c# parameter
sqlparameter paramoutput = new sqlparameter("@output", sqldbtype.nvarchar); paramoutput.direction = parameterdirection.output;
Comments
Post a Comment