Sybase

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDatabasesSybase

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old March 9th, 2014, 10:49 PM
sunck_hf sunck_hf is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Mar 2014
Posts: 1 sunck_hf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 18 sec
Reputation Power: 0
C# use odbc visit sybase procedure,why can't get output param value?

Procedure below

create procedure [dbo].[sp_get_ad_serial_number]
@table_name varchar(60) ,
@RecordID varchar(20) output
as
begin
declare
@yearmonth varchar(20) ,
@new_yearmonth varchar(20) ,
@num integer,
@ID decimal(38, 0)

select @yearmonth=convert(char(7),getdate(),111)
select @new_yearmonth=convert(char(6),getdate(),112)

begin tran
select @num=COUNT(1) from advanced_serial_number where table_name=@table_name and yearmonth=@yearmonth
if (@num=0)
begin
insert advanced_serial_number values(@table_name,@yearmonth,0)
select @ID =0
end
else
begin
update advanced_serial_number set id=id+1 where table_name=@table_name and yearmonth=@yearmonth
select @ID =id from advanced_serial_number where table_name=@table_name and yearmonth=@yearmonth
end

--print @yearmonth
---print @ID
commit tran
select @RecordID=@new_yearmonth+right('00000'+convert(var char(10),@ID),6)
print @RecordID
return 0
end


Program below


decimal d_serial = 0;
string v_serial = "";
using (OdbcConnection conn = new OdbcConnection(connectionString))
{
OdbcCommand cmd = new OdbcCommand("sp_get_ad_serial_number ?,?", conn);
cmd.CommandType = CommandType.StoredProcedure;
//cmd.Parameters.AddWithValue("@table_name", "ivr_task");
//cmd.Parameters.Add("@RecordID", OdbcType.VarChar, 20).Direction = ParameterDirection.Output;

OdbcParameter p1 = new OdbcParameter("@table_name", OdbcType.VarChar, 60);
p1.Direction = ParameterDirection.Input;
p1.Value = "ivr_task";
cmd.Parameters.Add(p1);
OdbcParameter p2 = new OdbcParameter("@RecordID", OdbcType.VarChar, 20);
p2.Direction = ParameterDirection.Output;
//p2.Value = "1";
cmd.Parameters.Add(p2);

try
{
conn.Open();
i=cmd. ExecuteNonQuery();
//cmd.ExecuteReader();
v_serial = p2.Value.ToString();
//d_serial = Convert.ToDecimal( cmd.Parameters["@RecordID"].Value.ToString());
}
catch (OdbcException ex)
{
status.Text = ex.Message+ "警告:调用ivr_task流水号失败!";//terminal_reimbursement
return;
}
finally
{
conn.Close();
}
}
TaskCD.Text = Convert.ToString(d_serial);


---------------
When c# Program execute,the sybase procedure is also execute,but output parameter value can't read

Last edited by sunck_hf : March 9th, 2014 at 11:52 PM.

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesSybase > C# use odbc visit sybase procedure,why can't get output param content?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap