publicclassSelfClass{//分站编号stringchStationNumber=string.Empty;//卡号stringsNumber=string.Empty;//天线stringsAntenna=string.Empty;//日期stringsDatatime=string.Empty;//...
public class SelfClass
{
//分站编号
string chStationNumber = string.Empty;
//卡号
string sNumber = string.Empty;
//天线
string sAntenna = string.Empty;
//日期
string sDatatime = string.Empty;
//定义右天线常量
///
/// Self_Variable:右天线变量值为1
///
private const int rightAntenna = 1;
//定义左天线常量
///
/// Self_Variable:左天线变量值为0
///
private const int leftAntenna = 0;
///
/// Self:接收传递过来的值
///
/// 分站编号
/// 人员卡号
/// 天线
/// 日期
public SelfClass(string chstation, string number, string antenna, string sdatatime)
{
this.chStationNumber = chstation;
this.sNumber = number;
this.sAntenna = antenna;
this.sDatatime = sdatatime;
}
///
/// Self:数据库处理线程的方法
///
public void thDataStart()
{
//新建连接
objMysqlconnection = new MySqlConnection(conn);
//执行查询语句
query = "SELECT markid from gs_gisdata_now WHERE markid = " + sNumber + "";
objMysqlcommand = new MySqlCommand(query, objMysqlconnection);
try
{
objMysqlconnection.Open();
objMysqlReader = objMysqlcommand.ExecuteReader();
//如果存在
if (objMysqlReader.Read() == true)
{
MessageBox.Show("执行更新操作!");
}
else
{
MessageBox.Show("执行插入操作!");
}
}
catch (MySqlException mse)
{
MessageBox.Show(mse.Message);
}
catch (Exception ecp)
{
MessageBox.Show(ecp.Message);
}
finally
{
objMysqlReader.Close();
objMysqlconnection.Close();
}
}
}
}
报了两个错:
Fatal error encountered during command execution.
未将对象引用设置到对象的实例。
还有为什么objMysqlReader为空,就是它为空才引起的:“Fatal error encountered during command execution.”错误!
展开