C# 2.0 Vista,sql2000带重临值存储进度调用

sql 2000 code:

C# 1
 1 DialogResult dr =MessageBox.Show(“是不是确实要去除?”, “提醒”, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
 2             if (dr == DialogResult.Yes)
 3             {
 4                 try
 5                 {
 6                     DBConnectioin dbc = new DBConnectioin();
 7                     SqlConnection conn = new SqlConnection(DBConnectioin.conStr);
 8                     conn.Open();
 9                     SqlCommand cmd = new SqlCommand(“Proc_Unite_Delete”, conn);//调用存储进程
10                     cmd.CommandType = CommandType.StoredProcedure;
11                     SqlParameter pares = new SqlParameter(“@UniteID”, SqlDbType.Int, 8);//输入参数
12                     SqlParameter pares1 = new SqlParameter(“@Return”, SqlDbType.VarChar, 30);//输出参数
13                     cmd.Parameters.Add(pares);
14                     cmd.Parameters.Add(pares1);
15                     cmd.Parameters[“@UniteID”].Value = Int32.Parse(this.txtUniteID.Text.Trim());
16                     cmd.Parameters[“@Return”].Direction = ParameterDirection.Output;
17                     cmd.ExecuteNonQuery();
18                     String Retur = (string)cmd.Parameters[“@Return”].Value;
19                     conn.Close();
20                     MessageBox.Show(“删除”+Retur, “提示”);
21                     this.FrmUnite_Load(sender, e);
22                 }
23                 catch (Exception ex)
24                 { }

 1C# 2IF EXISTS (SELECT name FROM sysobjects 
 2C# 3         WHERE name = ‘Proc_Unite_Delete’ AND type = ‘P’)
 3C# 4 DROP PROCEDURE Proc_Unite_Delete
 4C# 5GO
 5C# 6CREATE PROCEDURE  Proc_Unite_Delete
 6C# 7    @UniteID INT,
 7C# 8C#,        @Return VARCHAR(300) OUTPUT
 8C# 9AS
 9C# 10DECLARE @Ccount int, @Pcount int
10C# 11     SELECT @Ccount=COUNT(*) FROM C_Physician WHERE UniteID=@UniteID
11C# 12     SELECT @Pcount=COUNT(*) FROM Physician WHERE UniteID=@UniteID
12C# 13–SELECT @Ccount
13C# 14–SELECT @Pcount
14C# 15    IF exists(SELECT * FROM Unite WHERE UniteID=@UniteID) AND @Ccount=0 AND @Pcount=0        
15C# 16    BEGIN  
16C# 17         
17C# 18        DELETE FROM Unite            
18C# 19        WHERE UniteID=@UniteID
19C# 20        SET @Return=’成功’
20C# 21        –PRINT ‘OK’
21C# 22    RETURN 1
22C# 23    
23C# 24    END
24C# 25        SET @Return=’不成功’
25C# 26        –PRINT ‘NO’
26C# 27    RETURN 0
27C# 28    
28C# 29GO
29C# 30—测试代码
30C# 31DECLARE @srturn VARCHAR(300) ,@id int
31C# 32set @id=6
32C# 33EXEC Proc_Unite_Delete 6,@Return=@srturn OUTPUT
33C# 34SELECT @srturn

 

c#2.0 code:

 1C# 35DialogResult dr =MessageBox.Show(“是或不是确实要刨除?”, “提醒”, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
 2C# 36            if (dr == DialogResult.Yes)
 3C# 37C# 38            C# 39{
 4C# 40                try
 5C# 41C# 42                C# 43{
 6C# 44                    DBConnectioin dbc = new DBConnectioin();
 7C# 45                    SqlConnection conn = new SqlConnection(DBConnectioin.conStr);
 8C# 46                    conn.Open();
 9C# 47                    SqlCommand cmd = new SqlCommand(“Proc_Unite_Delete”, conn);//调用存储进程
10C# 48                    cmd.CommandType = CommandType.StoredProcedure;
11C# 49                    SqlParameter pares = new SqlParameter(“@UniteID”, SqlDbType.Int, 8);//输入参数
12C# 50                    SqlParameter pares1 = new SqlParameter(“@Return”, SqlDbType.VarChar, 30);//输出参数
13C# 51                    cmd.Parameters.Add(pares);
14C# 52                    cmd.Parameters.Add(pares1);
15C# 53                    cmd.Parameters[“@UniteID”].Value = Int32.Parse(this.txtUniteID.Text.Trim());
16C# 54                    cmd.Parameters[“@Return”].Direction = ParameterDirection.Output;
17C# 55                    cmd.ExecuteNonQuery();
18C# 56                    String Retur = (string)cmd.Parameters[“@Return”].Value;
19C# 57                    conn.Close();
20C# 58                    MessageBox.Show(“删除”+Retur, “提示”);
21C# 59                    this.FrmUnite_Load(sender, e);
22C# 60                }
23C# 61                catch (Exception ex)
24C# 62C# 63                C# 64{ }

相关文章