首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

改末行的代码先期,都可以正常显示出单价信息的,但是为什么现在运行后单价全都显示为0

2013-05-02 
改末行的代码之前,都可以正常显示出单价信息的,但是为什么现在运行后单价全都显示为0?private void getInf

改末行的代码之前,都可以正常显示出单价信息的,但是为什么现在运行后单价全都显示为0?
private void getInfo()
        {
            ID = textBox1.Text;
            SqlConnection con = cont.conn();
            SqlCommand com = new SqlCommand("select * from GoodsInfo where ID= '" + ID + "'", con);
            con.Open();
            SqlDataReader dr = com.ExecuteReader();
            dr.Read();
            GoodsName = dr.GetString(1);
            UnitPrice = dr.GetValue(3).ToString();
            GoodsAmount = dr.GetValue(3).ToString();
            con.Close();
            SqlDataAdapter da = new SqlDataAdapter("select * from GoodsInfo where ID= '" + ID + "'", con);
            DataSet ds = new DataSet();
            da.Fill(ds, "GoodsOrder");
            dataGridView1.Rows.Add(ID, GoodsName, UnitPrice, GoodsAmount);
        }
这个是我现在的代码,除去最后那行是我今天改的外,其他的部分+dataGridView1.DataSource = ds.Tables["GoodsOrder"];之前运行的时候,单价是可以显示出来的,但是现在单价全部都显示为0了,这是个什么情况?
数据库里的表,我把ID,GoodsName,UnitPrice和GoodsAmount都设置的是nvarchar(MAX)
[解决办法]
检查一下你的GetValue方法,把这个方法贴出来

热点排行