本帖最后由 mingjie_520 于 2010-10-29 13:31:55 编辑

解决方案 »

  1.   

    comPort_DataReceived中的代码是什么?
      

  2.   

    try
                {
                    string str = comPort.ReadExisting();
                    string strSql = "";
                    dtRs = null;
                    this.SQLQueryDB(strSql, ref dtRs);
                    if (dtRs.Rows.Count > 0)
                    {                    //}                    
                    }
                    else
                    {
                        //strSql = 
                        strSql = 
                        dtRs = null;
                        this.SQLQueryDB(strSql, ref dtRs);
                        if (dtRs.Rows.Count >0)
                        {
                            //strSql =""                        strSql = 
                            this.SQLQueryDB(strSql, ref dtRs1);
                            if (dtRs1.Rows .Count>0)
                            {
                                TimeSpan t=DateTime.Now.TimeOfDay.Subtract(Convert.ToDateTime(dtRs.Rows[0]["进厂时间"]).TimeOfDay);
                                if (t.Hours>=Convert.ToInt32(dtRs1.Rows[0]["间隔时间"]))
                                {
                                    strSql =
                                    this.SQLWork(strSql);
                                    this.SQLWork(strSql);                                this.SQLWork(strSql);
                                    this.SQLWork(strSql);   
                                    this.DBServerQuery(strSql, ref dtRs2);
                                    for (int ii = 0; ii < dtRs2.Rows.Count;ii++ )
                                    {
         
                                        this.DBServerWork(strSql);
                                    }
                                }
                            }
                        }
      

  3.   

     private void comPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
            {
                
                DataTable dtRs = null;
                DataTable dtRs1 = null;
                DataTable dtRs2 = null;
                
                try
                {
                    string str = comPort.ReadExisting();
                    string strSql = "
                    dtRs = null;
                    this.SQLQueryDB(strSql, ref dtRs);
                    if (dtRs.Rows.Count > 0)
                    {
                        strSql = "";
                        this.SQLWork(strSql);                    //strSql = "";
                        //this.SQLQueryDB(strSql, ref dtRs2);
                        //if (dtRs2.Rows.Count == 0)
                        //{
                            strSql = "";
                            this.SQLWork(strSql);
                        //}                    
                    }
                    else
                    {
                        //strSql = "";
                        strSql = "";
                        dtRs = null;
                        this.SQLQueryDB(strSql, ref dtRs);
                        if (dtRs.Rows.Count >0)
                        {
                            //strSql =""                        strSql = "";
                            this.SQLQueryDB(strSql, ref dtRs1);
                            if (dtRs1.Rows .Count>0)
                            {
                                TimeSpan t=DateTime.Now.TimeOfDay.Subtract(Convert.ToDateTime(dtRs.Rows[0]["进厂时间"]).TimeOfDay);
                                if (t.Hours>=Convert.ToInt32(dtRs1.Rows[0]["间隔时间"]))
                                {
                                    strSql ="";
                                    this.SQLWork(strSql);
                                    this.SQLWork(strSql);                                strSql = "";
                                    this.SQLWork(strSql);
                                    this.SQLWork(strSql);                                strSql = "";
                                    this.DBServerQuery(strSql, ref dtRs2);
                                    for (int ii = 0; ii < dtRs2.Rows.Count;ii++ )
                                    {
                                        strSql = "";
                                        this.DBServerWork(strSql);
                                    }
                                }
                            }
                        }
                        else
                        {                        string strInto = "请注意该车不能进厂!";
                            SpeechLib.SpeechVoiceSpeakFlags SpFlags = SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault;
                            SpeechLib.SpVoice Voice = new SpeechLib.SpVoice();
                            Voice.Voice = Voice.GetVoices(string.Empty, string.Empty).Item(0);
                            Voice.Speak(strInto, SpFlags);                    }
                    }            }
                catch (System.Exception ex)
                {
                    this.MsgBoxShow(ex.ToString());
                }
            }
    别看3楼的是这段
      

  4.   

    可能是在SQL语句中出了问题,比如 ...where a=12345 而你数据库里的字段是字符型的
    你最好是把异常堆栈贴出来,否则很难定位
      

  5.   

    自己解决,串口组件COM是多线程,要用委托来解决