采用串口接收数据,数据量 比较大,一秒几十条这样,开始运行是程序没有什么问题,数据也能入库。 几个小时也都没有问题,可是运行一个通宵后,第二天造成会跳出。
[b]未处理 System.IndexOutOfRangeException
Message="索引超出了数组界限。"
这样的错误 不知道有没有高手会知道如何修改 怎么回事呢。
string line = comm.ReadLine();
if (line[0] != '$' && line[0] != '!') return;//虽然可能有点垃圾,但是数据不重要。直接丢弃就可以了。后续的都是对的
int star = line.IndexOf("*", 1);//从line的line+1个字符起,查找1个字符,查找“*”在字符line的位置
if (star == -1) return;
SqlConnection conn = new SqlConnection("server = localhost;Initial Catalog =AIS;Integrated Security = True "); DataSet ds = new DataSet();
string strSqls;
strSqls = string.Format(@"insert into aisxx3(信息) values('{0}')", line.ToString());
SqlCommand c3 = new SqlCommand(strSqls, conn); try
{
conn.Open();
c3.ExecuteNonQuery();
}
接收的代码就是这样的
[b]未处理 System.IndexOutOfRangeException
Message="索引超出了数组界限。"
这样的错误 不知道有没有高手会知道如何修改 怎么回事呢。
string line = comm.ReadLine();
if (line[0] != '$' && line[0] != '!') return;//虽然可能有点垃圾,但是数据不重要。直接丢弃就可以了。后续的都是对的
int star = line.IndexOf("*", 1);//从line的line+1个字符起,查找1个字符,查找“*”在字符line的位置
if (star == -1) return;
SqlConnection conn = new SqlConnection("server = localhost;Initial Catalog =AIS;Integrated Security = True "); DataSet ds = new DataSet();
string strSqls;
strSqls = string.Format(@"insert into aisxx3(信息) values('{0}')", line.ToString());
SqlCommand c3 = new SqlCommand(strSqls, conn); try
{
conn.Open();
c3.ExecuteNonQuery();
}
接收的代码就是这样的
——————————————————————————
string line = comm.ReadLine();if (line == null || line.Length<=0) return; //增加这个代码,判断一下,可能是line没有东西if (line[0] != '$' && line[0] != '!') return;//虽然可能有点垃圾,但是数据不重要。直接丢弃就可以了。