多表访问,连接完后使用下面语句
thisCommand.CommandText="SELECT a.lcs from Sentence as a inner join Paragraph as p on a.paragraph_id=p.paragraph_id and p.article=50"; SqlDataReader thisReader=thisCommand.ExecuteReader(); textBox1.Text=Convert.ToString(thisReader["a.lcs"]);涉及到两个表Sentence(含有lcs、paragraph_id字段)、Paragraph(含有paragraph_id、article字段),目的是想通过表Paragraph中的article=50制约paragraph的取值,然后通过a.paragraph_id=p.paragraph_id来取表Sentence中的lcs字段,
哪位大虾帮忙看看,怎么实现,为什么到最后一行出错,还是原本上面的语句的问题?给出一个建议也可

解决方案 »

  1.   

    对 thisReader 进行循环取值,因为thisReader中不只包含一行数据。
    thisReader["a.lcs"] 调整为 thisReader[ 0 ][ "lcs" ];
      

  2.   

    sql自己在查询分析器里试一下不就知道了?
    p.article=50应该放在where里吧
      

  3.   

    字段名字错了改为:thisReader["lcs"]);
      

  4.   

    楼主的SQL语句好像都错了,你还是先把SQL放在查询分析器里面运行一下试试在说。
      

  5.   

    JadyWang(琦) 大虾:
    我把结果放在textBox中输出,如果是输出thisReader["lcs"],错误提示为:
    An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
    Additional information: Invalid attempt to read when no data is present.
    但是数据库中显然是有值的,肯定只是没有读取到
    如果输出是thisReader["a.lcs"],错误结果为:
    An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll
    Additional information: a.lcsCNet大虾:thisReader["a.lcs"] 调整为 thisReader[ 0 ][ "lcs" ];有错误,输出结果为:
    Cannot apply indexing with [] to an expression of type 'object'
    JadyWang大虾:改不改where结果是一样的
    ekin7913046大虾:在查询分析器里面运行可以