SqlDataAdapter da = new SqlDataAdapter(str, con); 
            da.Fill(dt); 
            MessageBox.Show(dt.Rows.Count.ToString());
            this.textBox2.Text = dt.Rows[0]["UserID"].ToString(); 
            this.richTextBox1.Text = dt.Rows[0]["Diary"].ToString(); 
            con.Close(); 
加上上面的代码,看看弹出的信息框是否有数据行。

解决方案 »

  1.   

    把sql代码打印出来看看有错没  估计是查询代码问题
      

  2.   

    string str = "select * from WorkDiary where CampanyName='" + this.comboBox1.Text + "' and Date='" + this.comboBox2.Text + "'"; 
    得到这个str,在sql中执行一下看看
      

  3.   

    报错:在位置0处没有任何行
    -------------------------
    有这个就可以确定了:没有读到任何数据填充到DataTable中。
      

  4.   

    string str = "select * from WorkDiary where CampanyName='" + this.comboBox1.Text + "' and Date='" + this.comboBox2.Text + "'"; 
    这句话在sql中就没有返回任何的东东。数据库里的date是什么类型的字段
      

  5.   

    有数据就是你的查询语句的问题,Date是日期型的字段吧?这个比较起来最麻烦了,使用参数再看看,另外,尽量不要使用容易混淆的词作字段名。
      

  6.   

    晕:你是datetime
    string str = "select * from WorkDiary where CampanyName='" + this.comboBox1.Text + "' and Date='" + this.comboBox2.Text + "'"; 
    你表里时间类型,在此等于。条件成立吗?
      

  7.   

    你先在sql里执行
    select top 1 [date] from workdiary看看是什么再在前台
    MessageBox.Show(this.comboBox2.Text);
    看看得到又是什么。问题应该在这里。
      

  8.   


    sql里
    消息 208,级别 16,状态 1,第 1 行
    对象名 'WorkDiary' 无效。messagebox:  2009-8-6  17:03
      

  9.   

    sql里 
    消息 208,级别 16,状态 1,第 1 行 
    对象名 'WorkDiary' 无效。 ------------------------
    到底有这个表没有?
      

  10.   

    string str = "select * from WorkDiary where CampanyName='" + this.comboBox1.Text.ToString().Trim() + "' and Date='" + this.comboBox2.Text.ToString().Trim() + "'"; 
    换成字符型的再比较吧