执行ExecuteReader() 就不能返回Parameters["ReturnValue"].Value啊?

jueban9818 2006-01-02 09:16:09
在存储过程里写了个select 和 return 返回值
ExecuteReader()后却不能接收这个返回值,
难道非要ExecuteNonQuery()才可以接收Parameters["ReturnValue"].Value 返回值么?
...全文
128 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zerocoin 2006-01-03
  • 打赏
  • 举报
回复
思归已经说得很明确了.受教了.
saucer 2006-01-02
  • 打赏
  • 举报
回复
no, you have to close the reader first

YourReader.Close();
//then get your output parameter
jueban9818 2006-01-02
  • 打赏
  • 举报
回复
明白了,原来光ExecuteReader()不能取得返回值得哦
singlepine 2006-01-02
  • 打赏
  • 举报
回复
public static DataSet GetList(int page_num,int row_in_page,string order_column,string comb_condition,ref int output)
{
string sql="tp_Fetch_List";
System.Data.SqlClient.SqlParameter[] p=new SqlParameter[5];

p[0]=new SqlParameter();
p[0].ParameterName ="@page_num";
p[0].Value =page_num;
p[0].DbType=System.Data.DbType.Int32;

p[1]=new SqlParameter();
p[1].ParameterName ="@row_in_page";
p[1].Value =row_in_page;
p[1].DbType=System.Data.DbType.Int32;

p[2]=new SqlParameter();
p[2].ParameterName ="@order_column";
p[2].Value =order_column;
p[2].DbType=System.Data.DbType.String;

p[3]=new SqlParameter();
p[3].ParameterName ="@row_total";
p[3].Direction=System.Data.ParameterDirection.Output;
p[3].DbType=System.Data.DbType.Int32;

p[4]=new SqlParameter();
p[4].ParameterName ="@comb_condition";
p[4].Value =comb_condition;
p[4].DbType=System.Data.DbType.String;
DataSet ds=ExecSPDataSet(sql,p);
if (p[3].Value!=DBNull.Value && p[3].Value.ToString()!=string.Empty )
output=Convert.ToInt32(p[3].Value);
return ds;
}

public static DataSet ExecSPDataSet(string sql,System.Data.IDataParameter[] paramers)
{
SqlConnection conn=new SqlConnection(ConnectionString);
SqlCommand sqlcom=new SqlCommand(sql,conn);
sqlcom.CommandType= CommandType.StoredProcedure ;

foreach(System.Data.IDataParameter paramer in paramers)
{
sqlcom.Parameters.Add(paramer);
}
conn.Open();

SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=sqlcom;
DataSet ds=new DataSet();
da.Fill(ds);

conn.Close();
return ds;
}

用ASP.NET做的 using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OleDb; /// /// Class1 的摘要说明 /// public class Class1 { private OleDbConnection m_Connection; private String m_brChar = "\n"; public Class1() { // // TODO: 在此处添加构造函数逻辑 // } private void ExecuteCommand(OleDbCommand cmd) { cmd.Connection=m_Connection; try { m_Connection.Open(); cmd.ExecuteNonQuery(); } finally { m_Connection.Close(); } } public DataSet GetNotes(DateTime fromDate, DateTime toDate) { DataSet ds=new DataSet(); OleDbDataAdapter da=new OleDbDataAdapter("select * from Notes where DateTime BETWEEN ? and ? ORDER BY DateTime DESC",m_Connection); da.SelectCommand.Parameters.Add("FromDate", OleDbType.Date).Value = fromDate.AddDays(1); m_Connection.Open(); da.Fill(ds,"MyNotes"); m_Connection.Close(); return ds; } public void InsertNote(string title,string contents) { OleDbCommand cmd =new OleDbCommand ("insert into Notes(Title,Contents) values(?,?)"); cmd.Parameters .Add ("Title",OleDbType .VarChar ).Value =title ; cmd.Parameters .Add ("Contents",OleDbType .LongVarChar ).Value =contents.Replace (m_brChar ,"
"); ExecuteCommand (cmd); } public void InsertComment(int noteid,string author,string email,string comment) { OleDbCommand cmd=new OleDbCommand ("insert into Comments(NoteID,Author,Email,Comment) values(?,?,?,?)"); cmd.Parameters .Add ("NoteID",OleDbType .VarChar ).Value =noteid; cmd.Parameters .Add ("Author",OleDbType .VarChar ).Value =author ; cmd.Parameters .Add ("Email",OleDbType .VarChar ).Value =email ; cmd.Parameters .Add ("Comment",OleDbType .LongVarChar ).Value =comment.Replace (m_brChar ,"
"); ExecuteCommand (cmd); } public void UpdaeNote(int noteid, string title, string contents) { OleDbCommand cmd = new OleDbCommand("UPDATE [Notes] SET [Title]=?,[Contents]=? WHERE [NoteID]=?"); cmd.Parameters.Add("Title", OleDbType.VarChar).Value = title; cmd.Parameters.Add("Contents", OleDbType.LongVarChar).Value = contents.Replace(m_brChar, "
"); cmd.Parameters.Add("NoteID", OleDbType.Integer).Value = noteid; ExecuteCommand(cmd); } public void UpdateComment(int commentid,string author,string email,string comment) { OleDbCommand cmd =new OleDbCommand ("UPDATE Comments SET Author =?,Email=?,Comment=? WHERE CommentID=?"); cmd.Parameters .Add ("Author",OleDbType .VarChar ).Value =author; cmd.Parameters .Add ("Comment",OleDbType .LongVarChar).Value =comment.Replace (m_brChar ,"
"); cmd.Parameters.Add("Email", OleDbType.VarChar).Value = email; cmd.Parameters.Add("CommentID", OleDbType.VarChar).Value = commentid; ExecuteCommand(cmd); } public void DeleteNote(int noteid) { OleDbCommand cmd =new OleDbCommand ("delete from Notes where NoteID="+noteid); ExecuteCommand(cmd); } public void DeleteComment(int commentid) { OleDbCommand cmd =new OleDbCommand ("delete from Comments where CommentID="+commentid); ExecuteCommand (cmd); } public void GetNoteData(int noteid,ref string title,ref string contents,ref string post_time) { OleDbCommand cmd=new OleDbCommand ("select * from Notes where NoteID="+ noteid ,m_Connection ); try { m_Connection .Open(); OleDbDataReader reader=cmd.ExecuteReader (CommandBehavior .CloseConnection ); if(reader .Read ()) { title =reader ["Title"].ToString (); contents =reader ["Contents"].ToString ().Replace ("
",m_brChar ); post_time =reader ["DataTime"].ToString (); reader .Close (); } } finally { m_Connection .Close (); } } public void GetCommentData(int commentid,ref string author,ref string email,ref string comment) { OleDbCommand cmd=new OleDbCommand ("select * from Comments where CommentID="+commentid ,m_Connection ); try { m_Connection .Open (); OleDbDataReader reader=cmd.ExecuteReader (CommandBehavior .CloseConnection ); if(reader.Read ()) { author =reader ["Author"].ToString (); email =reader ["Comment"].ToString ().Replace ("
",m_brChar ); reader .Close (); } } finally { m_Connection .Close (); } } } /// /// data 的摘要说明 ///
可对物料进行出入库登记、查询、统计等操作 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.Windows.Forms; namespace FORU_SMS_.BaseClass { public class DataClass { BaseClass.DataConn Dconn = new DataConn(); SqlDataAdapter Mysda; DataSet Myds; DataTable Mydt; SqlCommand SqlCom; //返回一个DataSet public DataSet GetDataSet(string sql, string dt) { Mysda = new SqlDataAdapter(sql, Dconn.OpenConn()); Myds = new DataSet(); Mysda.Fill(Myds, dt); return Myds; } //绑定ComboBox控件 public void BindComboBox(string sql, string dt, string Par_Name, ComboBox cbox) { Myds = GetDataSet(sql, dt); cbox.DataSource = Myds.Tables[dt]; cbox.DisplayMember = Par_Name; } //执行SQL语句,无返回值 public void ExecuteSql(string sql) { try { SqlCom = new SqlCommand(sql, Dconn.OpenConn()); SqlCom.ExecuteNonQuery(); } catch (Exception e) { throw new Exception(e.Message); } finally { Dconn.CloseConn(); } } //验证用户登陆 public bool ChkLogin(string txtUser, string txtPass) { bool strEnter = false; SqlCom = new SqlCommand("select count(*) from SMS_User where UserName=@txtUser AND Password=@txtPass", Dconn.OpenConn()); SqlParameter para = new SqlParameter("@txtUser",SqlDbType.VarChar,20); para.Value = txtUser; SqlCom.Parameters.Add(para); para = new SqlParameter("@txtPass", SqlDbType.VarChar, 20); para.Value = txtPass; SqlCom.Parameters.Add(para); int intCount = Convert.ToInt32(SqlCom.ExecuteScalar()); if (intCount > 0) { strEnter = true; } else { strEnter = false; } return strEnter; } public SqlDataReader GetRead(string sql) { SqlCom = new SqlCommand(sql, Dconn.OpenConn()); SqlDataReader sqlRead = SqlCom.ExecuteReader(CommandBehavior.CloseConnection); return sqlRead; } public DataTable GetDataTable(string sql) { SqlCom = new SqlCommand(sql, Dconn.OpenConn()); Mydt = new DataTable(); Mysda = new SqlDataAdapter(); try { Mysda.SelectCommand = SqlCom; Mysda.Fill(Mydt); } catch (Exception) { } finally { Dconn.CloseConn(); } return Mydt; } private bool isNumber(string s) { int Flag = 0; char[] str = s.ToCharArray(); for (int i = 0; i 0) { return true; } else { return false; } } public void saveGoods(AddGoods _Add) { string sql = ""; sql = sql "insert into SMS_Goods(GoodsID,GoodsName,StoreName,SupName,SpecName,UnitName,GoodsNum,GoodsPrice,GoodsAPrice,GoodsPeople,GoodsRemarks) values (@GoodsID,@GoodsName,@StoreName,@SupName,@SpecName,@UnitName,@GoodsNum,@GoodsPrice,@GoodsAPrice,@GoodsPeople,@GoodsRemarks)"; SqlCom = new SqlCommand(sql,Dconn.OpenConn()); Mysda = new SqlDataAdapter(); Mysda.SelectCommand = SqlCom; SqlCom.Parameters.Add("@GoodsID", SqlDbType.VarChar, 20, "GoodsID").Value = _Add.GoodsID; SqlCom.Parameters.Add("@GoodsName", SqlDbType.VarChar, 50, "GoodsName").Value = _Add.GoodsName; SqlCom.Parameters.Add("@StoreName", SqlDbType.VarChar, 50, "StoreName").Value = _Add.StoreName; SqlCom.Parameters.Add("@SupName", SqlDbType.VarChar, 50, "SupName").Value = _Add.SupName; SqlCom.Parameters.Add("@UnitName", SqlDbType.VarChar, 10, "UnitName").Value = _Add.UnitName; SqlCom.Parameters.Add("@GoodsNum", SqlDbType.Int, 4, "GoodsNum").Value = _Add.GoodsNum; SqlCom.Parameters.Add("@SpecName", SqlDbType.VarChar, 50, "SpecName").Value = _Add.SpecName; SqlCom.Parameters.Add("@GoodsPrice", SqlDbType.Float, 10, "GoodsPrice").Value = _Add.GoodsPrice; SqlCom.Parameters.Add("@GoodsAPrice", SqlDbType.Float, 10, "GoodsAPrice").Value = _Add.GoodsAPrice; SqlCom.Parameters.Add("@GoodsPeople", SqlDbType.VarChar, 20, "GoodsPeople").Value = _Add.GoodsPeople; SqlCom.Parameters.Add("@GoodsRemarks", SqlDbType.VarChar, 50, "GoodsRemarks").Value = _Add.GoodsRemarks; try { SqlCom.ExecuteNonQuery(); } catch (Exception) { } finally { Dconn.CloseConn(); } } } }

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧