private void listView_shipinfo_MouseClick(object sender, MouseEventArgs e)
{
string des_string = lvselecteditem();
SqlConnection Conn = new SqlConnection();
Conn.ConnectionString = "Server=Localhost;" +
"Trusted_Connection=yes;" +
"database=AIS_Receive";
Conn.Open();
SqlDataReader MyReader = null;
SqlCommand myCommand1 = new SqlCommand("select * from AIS_Receive.dbo.StaticInfo ,AIS_Receive.dbo.DynamicInfo where AIS_Receive.dbo.DynamicInfo.MMSI = AIS_Receive.dbo.StaticInfo.MMSI and AIS_Receive.dbo.StaticInfo.MMSI='" + des_string + "'", Conn);
MyReader = myCommand1.ExecuteReader();
MyReader.Read();
{ //将DynamicInfo表单里的数据到显示到界面
textBox_hangxingzhuangtai.Text = MyReader["nv_status"].ToString();//程序运行时,当点击列表框的条目时,系统在此条语句处报错变黄色并提示为 "Invalid attempt to read when no data is present",当把这条语句删去,又会在下面语句显示同样错误。
textBox_zhuanxiangsulv.Text = MyReader["rate_rate"].ToString();
textBox_duidisulu.Text = MyReader["speed_overgnd"].ToString();
textBox_GPSjingdu.Text = MyReader["gns_acc"].ToString();
textBox_jingdu.Text = MyReader["longitude"].ToString();
textBox_weidu.Text = MyReader["lantitude"].ToString();
textBox_UTC.Text = MyReader["utc"].ToString();
textBox_zhenhangxiang.Text = MyReader["ture_course"].ToString();
//将StaticInfo表单里的数据到显示到界面
textBox_IMO.Text = MyReader["IMO"].ToString();
textBox_chuanleixing.Text = MyReader["ship_type"].ToString();
textBox_chuanchang.Text = MyReader["ship_length"].ToString();
textBox_chuankuan.Text = MyReader["ship_width"].ToString();
textBox_tianxianweizhi.Text = MyReader["ante_pos"].ToString();
textBox_ETA.Text = MyReader["eta"].ToString();
textBox_chishui.Text = MyReader["eatwater"].ToString();
textBox_dingweizhuangzhi.Text = MyReader["pos_dev"].ToString();
}
Conn.Close();
return ;
}
// 备注说明:数据库里的表里已经存入数据了,下面的函数功能就是当鼠标点击界面列表框里的一项时,程序调用数据库里的数据并显示到对应界面里的每一项textbox中,StaticInfo和DynamicInfo为两张表单。确信数据库已经打开,但就是读不出数据显示不到界面上还报错