各位大俠 程序錯在哪裡了
public int theNumber()
{
int i=0;
string Str = "SELECT SUM(member) FROM tempcar";
SqlConnection sqlConn = new SqlConnection(myConn);
SqlCommand sqlComm = new SqlCommand();
sqlComm.CommandText = Str;
sqlComm.Connection = sqlConn;
sqlConn.Open();
try
{
System.Data.SqlClient.SqlDataReader myRed = sqlComm.ExecuteReader();
if(myRed.HasRows)
{
while(myRed.Read())
{
return i = Convert.ToInt16 (myRed.GetValue(0));
}
}
else
return i;
}
catch(Exception)
{
return i;
}
sqlConn.Close();
}
------------------------------------------------------------------------
錯誤:部分程序並沒傳回值
各位大俠 程序錯在哪裡了
问题点数:0、回复次数:3Top
1 楼97ce_twinkle(毛毛虫)回复于 2004-11-02 11:05:50 得分 0
while 外层还要return吧Top
2 楼liuliulch(未知多)回复于 2004-11-02 11:20:29 得分 0
sqlConn.Close();后面添加 return i;
如果都有返回值,sqlConn.Close()是不会执行的吧,
将某些return i 动一动吧Top
3 楼xzcxlyh(程序人生)回复于 2004-11-02 11:50:03 得分 0
public int theNumber()
{
int i=0;
string Str = "SELECT SUM(member) FROM tempcar";
SqlConnection sqlConn = new SqlConnection(myConn);
SqlCommand sqlComm = new SqlCommand();
sqlComm.CommandText = Str;
sqlComm.Connection = sqlConn;
sqlConn.Open();
try
{
System.Data.SqlClient.SqlDataReader myRed = sqlComm.ExecuteReader();
if(myRed.HasRows)
{
while(myRed.Read())
{
return i = Convert.ToInt16 (myRed.GetValue(0));
}
}
else
return i;
}
catch(Exception)
{
return i;
}
finally
{
sqlConn.Close();
}
}
------------------------------------------------------------------------Top




