111,131
社区成员
发帖
与我相关
我的任务
分享 SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand thisCommand = new SqlCommand("select sum(point) as count from test where stuId='" + stuId + "'and courseName='" + courseName + "'and type='" + type+ "'", myConnection);
myConnection.Open();
SqlDataReader thisReader = thisCommand.ExecuteReader();
int count = 0;
if (thisReader== null)
{
return 0;
}
if (thisReader.Read())
{
count = thisReader.GetInt32(0);
}
thisReader.Close();
myConnection.Close();
return count;
if (thisReader.GetSchemaTable().Rows.Count == 0)
{
return 0;
}
//应该是这样吧?
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand thisCommand = new SqlCommand("select sum(point) as count from test where stuId='" + stuId + "'and courseName='" + courseName + "'and type='" + type+ "'", myConnection);
myConnection.Open();
SqlDataReader thisReader = thisCommand.ExecuteReader();
int count = 0;
if (thisReader== null)
{
return 0;
thisReader.Close();
myConnection.Close();
}
if (thisReader.Read())
{
count = Int32.Parse(thisReader["count"].ToString());
}
thisReader.Close();
myConnection.Close();
return count;
catch (Exception ex)
{
Response.Write(ex.ToString());
Response.End();
}
finallyif(thisRead.HasRows)//记录集是否为空
{
while(thisRead.Read())
{
.....
}
}