求教提示(指定的转换无效)怎么解决 本帖最后由 mingjie_520 于 2010-10-29 13:31:55 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 comPort_DataReceived中的代码是什么? 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); } } } } 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楼的是这段 可能是在SQL语句中出了问题,比如 ...where a=12345 而你数据库里的字段是字符型的你最好是把异常堆栈贴出来,否则很难定位 自己解决,串口组件COM是多线程,要用委托来解决 如何设置解决方案,使得两个exe按设定次序运行 dataGridView dataset如何转成EXCEL档 数据上传 RichTextBox插入图片问题 高手请进:同页面2个GridView的2列复选框记录取值问题!在线等! C#网络纸牌游戏求助!! C# gdi自绘列表项热点问题 !高手推荐关于讲述深层面向对象语言原理的书!up给分! 如何调用win32 api 多串口接收数据 C# 多串口编程问题
{
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);
}
}
}
}
{
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楼的是这段
你最好是把异常堆栈贴出来,否则很难定位