C# 2.0 Vista,sql2000带返回值存储过程调用

SQL CODE:

<textarea cols="50" rows="15" name="code" class="c-sharp:showcolumns">IF EXISTS (SELECT name FROM sysobjects WHERE name = 'Proc_Unite_Delete' AND type = 'P') DROP PROCEDURE Proc_Unite_Delete GO CREATE PROCEDURE Proc_Unite_Delete @UniteID INT, @Return VARCHAR(300) OUTPUT AS DECLARE @Ccount int, @Pcount int SELECT @Ccount=COUNT(*) FROM C_Physician WHERE UniteID=@UniteID SELECT @Pcount=COUNT(*) FROM Physician WHERE UniteID=@UniteID --SELECT @Ccount --SELECT @Pcount IF exists(SELECT * FROM Unite WHERE UniteID=@UniteID) AND @Ccount=0 AND @Pcount=0 BEGIN DELETE FROM Unite WHERE UniteID=@UniteID SET @Return='成功' --PRINT 'OK' RETURN 1 END SET @Return='不成功' --PRINT 'NO' RETURN 0 GO ---测试代码 DECLARE @srturn VARCHAR(300) ,@id int set @id=6 EXEC Proc_Unite_Delete 6,@Return=@srturn OUTPUT SELECT @srturn</textarea>

 

 

c#2.0 CODE:

 

<textarea cols="50" rows="15" name="code" class="c-sharp">DialogResult dr =MessageBox.Show("是否真的要删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { try { DBConnectioin dbc = new DBConnectioin(); SqlConnection conn = new SqlConnection(DBConnectioin.conStr); conn.Open(); SqlCommand cmd = new SqlCommand("Proc_Unite_Delete", conn);//调用存储过程 cmd.CommandType = CommandType.StoredProcedure; SqlParameter pares = new SqlParameter("@UniteID", SqlDbType.Int, 8);//输入参数 SqlParameter pares1 = new SqlParameter("@Return", SqlDbType.VarChar, 30);//输出参数 cmd.Parameters.Add(pares); cmd.Parameters.Add(pares1); cmd.Parameters["@UniteID"].Value = Int32.Parse(this.txtUniteID.Text.Trim()); cmd.Parameters["@Return"].Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); String Retur = (string)cmd.Parameters["@Return"].Value; conn.Close(); MessageBox.Show("删除"+Retur, "提示"); this.FrmUnite_Load(sender, e); } catch (Exception ex) { }</textarea>

你可能感兴趣的:(sql,exception,String,C#,delete,存储)