用于数据类型的SqlDataReader和SelectedItem在Combobox中的时间 [英] SqlDataReader and SelectedItem for data type Time in Combobox

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

问题描述

大家好,

我有这个代码应该读取数据类型Time然后SelectItem,但它没有选择Item。我该怎么改变它?谢谢!

这是我填写它的方式:

  void  vypl_comboboxy( )
{


spojeni.Open();
var cb1 = new SqlCommand( SELECT odjezd FROM stanice WHERE akce ='
+ selectrowid + 'ORDER BY odjezd ASC,spojeni);
SqlDataReader dr1 = cb1.ExecuteReader();
while (dr1.Read())
{
comboBox1.Items.Add(dr1 [ odjezd]);

}
dr1.Close();
dr1.Dispose();



这就是我想要在数据类型中选择项目的时间

 SqlCommand novyprikaz =  new  SqlCommand(  SELECT * FROM klient WHERE ID_K = + selectrowid,spojeni); 
spojeni.Open();
SqlDataReader precti = novyprikaz.ExecuteReader();

if (precti.Read())
{
comboBox1.SelectedItem = precti.GetTimeSpan( 16 )的ToString();
}

解决方案

您正在组合框中添加对象类型并将字符串类型设置为所选项目。它不起作用。



在组合框中添加字符串类型,如



 comboBox1.Items.Add(dr1 [  odjezd]。ToString()); 





以及selectedItem为字符串



comboBox1.SelectedItem = precti。 GetTimeSpan(16)的ToString();


Hello guys,
I have this code which should read data type Time and then SelectItem,but it doesn't select Item. How should I change it ? thanks!
This is how I fill it:

void vypl_comboboxy()
        {
            

                spojeni.Open();
                var cb1 = new SqlCommand("SELECT odjezd FROM stanice WHERE akce='"
                                + selectrowid+ "' ORDER BY odjezd ASC", spojeni);
 SqlDataReader dr1 = cb1.ExecuteReader();
                while (dr1.Read())
                {
                    comboBox1.Items.Add(dr1["odjezd"]);

                }
                dr1.Close();
                dr1.Dispose();


This is how I want to select item in data type Time

SqlCommand novyprikaz = new SqlCommand("SELECT * FROM klient WHERE ID_K=" + selectrowid, spojeni);
                spojeni.Open();
                SqlDataReader precti = novyprikaz.ExecuteReader();

                if (precti.Read())
                {
 comboBox1.SelectedItem = precti.GetTimeSpan(16).ToString();
}

解决方案

You are adding Object type in combobox and setting string type as selected Item. It won't work.

Add string type in combo box like

comboBox1.Items.Add(dr1["odjezd"].ToString());



and also the selectedItem as string

comboBox1.SelectedItem = precti.GetTimeSpan(16).ToString();


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

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