SqlDataReader如何返回调用。请问错在哪儿呀 md=myread1(mystring);//請問是不是不能這樣做的呀 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void SqlDataReader myread1(string mystr1) { SqlConnection SqlConn1=new SqlConnection(ConnString); SqlDataReader thisread=null; try { SqlConn1.Open (); SqlCommand mycomand=new SqlCommand (mystr1,SqlConn1); thisread=mycomand.ExecuteReader (CommandBehavior.CloseConnection); return thisread; } catch { throw new ExecutionEngineException (); } }________________________________________________________________________string mystring="select * from xxx";SqlDataReader md;md=myread1(mystring);while(md.Read ()){Response.Write (md["字段名1"]);} 基本上找到原因﹐但不明白。請看private void Page_Load(object sender, System.EventArgs e){SqlConn=new SqlConnection (ConnString);//SqlConn變量我在函數外面單獨申明了private SqlCommand mycom;try{SqlConn.Open ();SqlCommand Cmd=new SqlCommand ("select * from groups",SqlConn);myread=Cmd.ExecuteReader ();while(myread.Read ()) { Response.Write (myread["groupname"]); }}catch{throw;}}_________________________________________________________________________________下面是一樣的呀﹐只是SqlConn變量在函數量申明。請看。。private void Page_Load(object sender, System.EventArgs e){/*SqlConnection SqlConn1=new SqlConnection(ConnString);//唯一就是SqlConnn1變量地方不同呀。try { SqlConn1.Open (); SqlCommand mycomand=new SqlCommand ("select * from groups",SqlConn1); SqlDataReader thisread; thisread=mycomand.ExecuteReader(); while(thisread.Read ()){Response.Write (myread["groupname"]);} }catch{throw ;}}*/ //SqlConn變量我在函數外面單獨申明了private SqlCommand mycom;這句打錯了。//SqlConn變量我在函數外面單獨申明了private SqlConnection SqlConn; 哪位帮忙看一下是什幺原因﹐看过很多书﹐总觉得撑握的差不多了﹐没想到一动手﹐最基础的东东都过不去。唉。看看吧﹐我根据书上看的知认实在不知为什幺﹐第一种情况运行一点问题都没有﹐为什幺第二种写法就行不通。就是一个SqlConnection,及SqlCommand变量申明位置不同呀﹐一个是在Page_Load函数外(这样就行)﹐一个是在Page_Load函数内(这样不行)﹐不知怎幺回事呀。。 在WPF中,如何实现跨进程下,一个窗体总是悬挂在另外一个窗体之上。 请教Devexpress组件中图片缩放的问题 c1FlexGrid如何实现列的别名(紧急求助,分不够再加) 关于使用c#监控剪切板的问题 刚接触c#,非常简单的问题!谢谢大家! 求惠通短信猫开发包例程 大家谁用过亿恩科技[ENKJ.COM]的虚拟主机吗? 如何传递窗体控件或对象? [Question]如何采集多媒体数据 C中的 char* 在C#中用什么来替代,不要说用 char* 指针 求解决方案(分不够再加)先给70分 有关动态模拟的设计?
{
SqlConnection SqlConn1=new SqlConnection(ConnString);
SqlDataReader thisread=null;
try
{
SqlConn1.Open ();
SqlCommand mycomand=new SqlCommand (mystr1,SqlConn1);
thisread=mycomand.ExecuteReader (CommandBehavior.CloseConnection);
return thisread;
}
catch
{
throw new ExecutionEngineException ();
}
}
________________________________________________________________________
string mystring="select * from xxx";
SqlDataReader md;
md=myread1(mystring);
while(md.Read ())
{
Response.Write (md["字段名1"]);
}
private void Page_Load(object sender, System.EventArgs e)
{
SqlConn=new SqlConnection (ConnString);
//SqlConn變量我在函數外面單獨申明了private SqlCommand mycom;
try
{
SqlConn.Open ();
SqlCommand Cmd=new SqlCommand ("select * from groups",SqlConn);
myread=Cmd.ExecuteReader ();
while(myread.Read ())
{
Response.Write (myread["groupname"]);
}
}
catch{throw;}}
_________________________________________________________________________________
下面是一樣的呀﹐只是SqlConn變量在函數量申明。請看。。
private void Page_Load(object sender, System.EventArgs e)
{
/*SqlConnection SqlConn1=new SqlConnection(ConnString);
//唯一就是SqlConnn1變量地方不同呀。
try
{
SqlConn1.Open ();
SqlCommand mycomand=new SqlCommand ("select * from groups",SqlConn1);
SqlDataReader thisread;
thisread=mycomand.ExecuteReader();
while(thisread.Read ())
{
Response.Write (myread["groupname"]);
}
}
catch{throw ;}}*/
這句打錯了。
//SqlConn變量我在函數外面單獨申明了private SqlConnection SqlConn;
看看吧﹐我根据书上看的知认实在不知为什幺﹐第一种情况运行一点问题都没有﹐为什幺第二种写法就行不通。就是一个SqlConnection,及SqlCommand变量申明位置不同呀﹐一个是在Page_Load函数外(这样就行)﹐一个是在Page_Load函数内(这样不行)﹐不知怎幺回事呀。。