多表访问,连接完后使用下面语句
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字段,
哪位大虾帮忙看看,怎么实现,为什么到最后一行出错,还是原本上面的语句的问题?给出一个建议也可
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字段,
哪位大虾帮忙看看,怎么实现,为什么到最后一行出错,还是原本上面的语句的问题?给出一个建议也可
thisReader["a.lcs"] 调整为 thisReader[ 0 ][ "lcs" ];
p.article=50应该放在where里吧
我把结果放在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大虾:在查询分析器里面运行可以