数据数据类型的SqlDataReader [英] SqlDataReader for numeric data type

查看:126
本文介绍了数据数据类型的SqlDataReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有这个代码:



  public   void  chyt_data()
{

SqlCommand novyprikaz = new SqlCommand ( SELECT * FROM table WHERE akce = + nc_zajezd_vyber,spojeni);
spojeni.Open();
SqlDataReader precti = novyprikaz.ExecuteReader();

if (precti.Read())
{
...
zcena1.Text = precti.GetDecimal( 4 )。ToString();
zcena2.Text = precti.GetDecimal( 5 )。ToString();
zcena3.Text = precti.GetDecimal( 6 )。ToString();

}
spojeni.Close();
}







它从我的SQL数据库表中读取数据并读取它们,问题是它没有读取zcena1,zcena2和zcena3,因为SQL表中的数据类型是数字,在microsoft的网站上写的是我应该用GetDecimal读取它,但它也不起作用。

有什么解决方案吗?



提前致谢!

解决方案

zcena1.Text = precti [columnName /索引]的ToString();

Hello guys, I have this code:

public void chyt_data()
        {
        
            SqlCommand novyprikaz = new SqlCommand("SELECT * FROM table WHERE akce="+nc_zajezd_vyber, spojeni); 
            spojeni.Open();
            SqlDataReader precti = novyprikaz.ExecuteReader();

            if (precti.Read())
            {
...
                zcena1.Text = precti.GetDecimal(4).ToString();
                zcena2.Text = precti.GetDecimal(5).ToString();
                zcena3.Text = precti.GetDecimal(6).ToString();
            
            }
            spojeni.Close();
        }




It seelcts data and reads them from my SQL DB table, problém is that It doesnt read zcena1,zcena2 and zcena3, its because the data type in SQL table is numeric, on microsoft's website was written that i should read it with GetDecimal, but it doesn't work either.
Is there any solution?

Thanks in advance!

解决方案

zcena1.Text=precti[columnName/index].ToString();


这篇关于数据数据类型的SqlDataReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆