foreach (DataRow dr in dtData.Rows.Cast<DataRow>().ToList())
解决方案 »
- 【求助】欲在用C#写的聊天程序中调用微软翻译API,但注册申请时遇到问题
- C#控制台程序怎么调用cmd的命令
- c# 连接池有个2个参数不明白,请高手给解释一下谢谢
- C#调用C Dll怎么传结构指针啊
- 事务处理,在一个事务中提交了更新操作,返回也是正确的,但是查询结果却一直没变,10分钟后才更新
- C#中如何实现VC中的OnEraseBkgnd()消息函数?? 在线等!!!!!!!!!
- 请问C#调用Dll中参数指针应该怎么声明?
- Outlook Express 的*.dbx文件!
- 数据表是否允许为空的判断
- 新人,想请教关于水晶报表setparametervalue方法的问题
- itextsharp 生成表格的边框问题
- 请懂的朋友解释下这段代码,看的卡壳了,是有关directshow的。
foreach里面有代码对dtdata进行添加和移除的操作,这是不允许的。
你可以用中间变量记录一下要增加和移除的对象,循环结束后在进行添加和移除操作
而且你…………没有单步调试吗?先单步调试一下,找到真正出错的语句再说吧!
//if (EMMSEND)
{
// if (receiveflag == true)
// { string ConnMdbStr = "Data Source='" + txtsqlip.Text + "' ;Initial Catalog='" + dataname.Text + "';User ID=sa;Password='" + txtpassword.Text + "'";
SqlConnection ConnMdb = new SqlConnection(ConnMdbStr);
string SqlText = "SELECT * FROM Group_SGK3 ";
SqlDataAdapter da = new SqlDataAdapter(SqlText, ConnMdb);
try
{
//da.Fill(dt);
dtData.Clear();
da.Fill(dtData); }
catch
{
break;
}
//} foreach (DataRow dr in dtData.Rows.Cast<DataRow>().ToList()) //遍历行 in 行的集合
{
byte[] EDS = new byte[183];
EDS[0] = 0x82; // emm table id
EDS[1] = 0x40; //
EDS[2] = 0x3f;
EDS[3] = 0x02;// emm secton length
byte[] groupid = HexStrToHexBytes(dr["Group_name"].ToString());
EDS[4] = groupid[0];
EDS[5] = groupid[1];
// emm secton length
//发送emm
string strConn = "Data Source=127.0.0.1;Initial Catalog=zy;User ID=sa;Password=229107my229107m";
SqlConnection ConnAcc = new SqlConnection(strConn);
string strSQL = "SELECT * FROM Group_SGK3 ";
SqlDataAdapter de = new SqlDataAdapter(strSQL, ConnMdb);
try
{
//da.Fill(dt);
dtData.Clear();
de.Fill(dtData); }
catch
{
break;
}
for (int n = 0; n < 7; n++)
{
int GK;
foreach (DataRow rdr in dtData.Rows)
{ int SGK = Convert.ToInt32(rdr["SGK"]);
GK = SGK << n;
if (Convert.ToBoolean(rdr["state1"]))
{
byte[] gk = new byte[8];
Array.Copy(HexStrToHexBytes(GK.ToString()), 0, gk, 7, 1);
SKeyValue = SKeyValue1;
byte[] EncryptSk = EncryptDES(SKeyValue, gk);
EDS[6] = 0x01;
Array.Copy(EncryptSk, 0, EDS, 7, EncryptSk.Length);
//Thread.Sleep(5);
}
else
{
// byte[] EDS = new byte[183]; EDS[6] = 0x01;
EDS[7] = 0xff;
EDS[8] = 0xff;
for (int i = 9; i < 15; i++)
{
EDS[i] = 0x00; } }
if (Convert.ToBoolean(rdr["state2"]))
{
byte[] gk = new byte[8];
Array.Copy(HexStrToHexBytes(GK.ToString()), 0, gk, 7, 1);// pdk buf: 0,0,0,0,0,0,0,0xcd
SKeyValue = SKeyValue2;
byte[] EncryptSk = EncryptDES(SKeyValue, gk);
EDS[15] = 0x02;
Array.Copy(EncryptSk, 0, EDS, 16, EncryptSk.Length); }
else
{
EDS[16] = 0xff;
EDS[17] = 0xff;
for (int i = 18; i < 24; i++)
{
EDS[i] = 0x00; }
}
if (Convert.ToBoolean(rdr["state3"]))
{
byte[] gk = new byte[8];
Array.Copy(HexStrToHexBytes(GK.ToString()), 0, gk, 7, 1);// pdk buf: 0,0,0,0,0,0,0,0xcd
SKeyValue = SKeyValue3;
byte[] EncryptSk = EncryptDES(SKeyValue, gk);
EDS[24] = 0x03;
Array.Copy(EncryptSk, 0, EDS, 25, EncryptSk.Length); }
{
EDS[24] = 0x03;
EDS[25] = 0xff;
EDS[26] = 0xff;
for (int i = 27; i < 33; i++)
{
EDS[i] = 0x00; } }
if (Convert.ToBoolean(rdr["state4"]))
{
byte[] gk = new byte[8];
Array.Copy(HexStrToHexBytes(GK.ToString()), 0, gk, 7, 1);
SKeyValue = SKeyValue4;
byte[] EncryptSk = EncryptDES(SKeyValue, gk);
EDS[33] = 0x04;
Array.Copy(EncryptSk, 0, EDS, 34, EncryptSk.Length);
Thread.Sleep(5);
}
else
{
EDS[34] = 0xff;
EDS[35] = 0xff;
for (int i = 36; i < 42; i++)
{
EDS[i] = 0x00; } }
for (int i = 42; i < 183; i++)
{
EDS[i] = 0xff; } MsgSend(TcpSocket, (int)Msg_Type_Value.Data_provision, SendBytes, EDS);
InsertMsgLineWithTime("分组用户授权信息发送");
Thread.Sleep(10); }
}
}
string SqlTex = "SELECT * FROM User_S2 ";
SqlDataAdapter ds = new SqlDataAdapter(SqlTex, ConnMdb);
try
{
//da.Fill(dt);
dtData.Clear();
ds.Fill(dtData);
}
catch
{
break;
}
foreach (DataRow dr in dtData.Rows)
{
byte[] EDS = new byte[183];
EDS[0] = 0x82; // emm table id
EDS[1] = 0x40; //
EDS[2] = 0x3f;
EDS[3] = 0x01;
byte[] pdk = new byte[8];
Array.Copy(HexStrToHexBytes(dr["pdk"].ToString()), 0, pdk, 7, 1);// pdk buf: 0,0,0,0,0,0,0,0xcd
byte[] sgroupid = HexStrToHexBytes(dr["SGroup_name"].ToString());
byte[] SGK = new byte[8];
Array.Copy(HexStrToHexBytes(dr["SGK"].ToString()), 0, SGK, 7, 1);
byte[] EncryptSk = EncryptDES(SGK, pdk);
byte[] sgroup_id = HexStrToHexBytes(dr["SGroup_id"].ToString());
EDS[4] = (byte)sgroupid[0];
EDS[5] = (byte)sgroupid[1];
EDS[6] = (byte)sgroup_id[0];
EDS[7] = (byte)sgroup_id[1];
Array.Copy(EncryptSk, 0, EDS, 8, EncryptSk.Length);
int i;
for (i = 8 + EncryptSk.Length; i < EDS.Length; i++)
{
EDS[i] = 0xff; }
MsgSend(TcpSocket, (int)Msg_Type_Value.Data_provision, SendBytes, EDS);
InsertMsgLineWithTime("超组用户分组数据发送");
Thread.Sleep(10); }
SqlText = "SELECT * FROM stack ";
ds = new SqlDataAdapter(SqlTex, ConnMdb);
try
{
//da.Fill(dt);
dtData.Clear();
ds.Fill(dtData);
}
catch
{
break;
}
foreach (DataRow dr in dtData.Rows)
{
break;
} EMMSEND = false;
}