2 xingyueyeholy xingyueyeholy 于 2013.07.11 18:39 提问

VS2010用C#将数据库里的数据读出并显示到界面时 出错,求各位老师帮忙
a adb

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为两张表单。确信数据库已经打开,但就是读不出数据显示不到界面上还报错
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!