首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

循环插入数据有关问题

2012-01-14 
循环插入数据问题for(intj0jRowsj++){//生成随机字符串for(inti0istrLengthi++){strRandom+aryCh

循环插入数据问题
for(int   j=0   ;   j   <   Rows;   j++)
{
//生成随机字符串
for(   int   i=0;   i   <   strLength;   i++   )
{
strRandom   +=aryChar[Rnd.Next(   aryChar.Length   )];
}

strRandom   =strRandom+num;
string   sql   =   "Insert   into   edu_card(card_id)   values( ' "+strRandom+ " ') ";
include.insertData(sql);
}

第二次循环的时候把上一次的值也插入进数据库了`
123
123asd
123asdert
那里出了问题?


[解决办法]
j循环内先把strRandom清空。
[解决办法]
for(int j=0 ; j < Rows; j++)
{
strRandom=null;//或者0,看是什么类型
//生成随机字符串
for( int i=0; i < strLength; i++ )
{

strRandom +=aryChar[Rnd.Next( aryChar.Length )];
}

strRandom =strRandom+num;
string sql = "Insert into edu_card(card_id) values( ' "+strRandom+ " ') ";
include.insertData(sql);
}

热点排行