xingyueyeholy 2013-07-11 10:39
浏览 2598

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

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为两张表单。确信数据库已经打开,但就是读不出数据显示不到界面上还报错
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图点聚合中Marker的位置无法实时更新
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程