行 220:if((Convert.ToInt32((myReader.GetDateTime(3)).Month)==brithMonth)&& (Convert.ToInt32((myReader.GetDateTime(3).Day))==brithDay))
行 221: {
行 222: m[i]=myReader.GetInt32(0);
行 223: i++;
行 224://SqlCommand cmd=new SqlCommand("update userGBRecord set userGB=userGB+'"+userGb+"'",con);
首先是类型的转换,这个把他写得工整一点就能解决
DateTime tmp = Convert.ToDateTime(myReader[3]);
if(tmp.Month ==brithMonth && tmp.Day ==brithDay)
{
m[i]=Convert.ToInt32(myReader[0]);
i++;
}
要对数组m中的元素进行赋值,首先要先定义数组的长度:
int[] m = new int[100]; //但是这个长度是未知的,所以要用动态数组System.Collections.ArrayList al = new System.Collections.ArrayList();
while(myReader.Read())
{
al.Add(Convert.ToInt32(myReader[0]));
//........
}
int[] m = new int[al.Count];
al.CopyTo(m,0);//最后获得这个int数组
------------------------------------------最后是SqlCommand的问题需要提醒楼主,cmd和myReader不能使用同一个connection,众所周知,dataReader在读取数据时是要保持数据库连接的,不能再背其它sqlcommand使用,用则抱错~
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IndexOutOfRangeException: 索引超出了数组界限。源错误:
行 238: SqlConnection con1=adminOperate.creatcon();
行 239: con1.Open();
行 240: SqlCommand cmd=new SqlCommand("update userGBRecord set userGB=userGB+'"+userGb+"'where userID='"+m[al.Count]+"'",con1);
行 241: for(int j=0;j<al.Count;j++)
行 242: {
上边了2中方法我都试过了 好象都不行啊