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 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了