comboBox1.SelectedValue.ToString();这样?

解决方案 »

  1.   

    winform的话,应该是:SelectedItem
    if (comboBox1.SelectedIndex == -1)
                {
                    MessageBox.Show("请选择一项");
                    return;
                }            string description = comboBox1.SelectedItem.ToString();
      

  2.   

     textBox1.Text = ds.Tables[0].Rows[0]["test_daima"].ToString();
    如果这儿没有报错就表示你取到值了,只不过为空的
      

  3.   

    就是在那里报错,但是如果把 textBox1.Text = ds.Tables[0].Rows[0]["test_daima"].ToString();注释掉的话能够在datagridview中得到查询的数据额
      

  4.   

    ...⊙﹏⊙‖∣明显是没数据嘛,我还以为你问的是combobox呢。
    if(ds.Tables[0].Rows.count>0)
    {
    .....
    }
    else
    {
    //没数据
    }
      

  5.   

     textBox1.Text = ds.Tables[0].Rows[0]["test_daima"].ToString();
    这句话拿掉,
    单独执行
    dg1.DataSource = ds.Tables[0].DefaultView;
    看表格里到底显示什么东西
      

  6.   

    调试状态下把你的鼠标放到Tables或Rows上,看看里面到底有没有数据
      

  7.   


    在 这句:DataSet ds = DBHepler.GetDataSet(sql);前面设个断点,获得sql这个变量的实例值,然后去数据库界面执行一下,看看查询结果有没有数据,注意不包含列名。 textBox1.Text = ds.Tables[0].Rows[0]["test_daima"].ToString();
    这句代码是正确的,不需要怀疑,只要test_daima这个字段存在就OK。