NextResult()问题
string strcnn= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\vsio\\mydata.mdb ";
string sql= "select xuehao,score from score;select num,xuehao,name from student ";
OleDbConnection connection=new OleDbConnection(strcnn);
try
{
connection.Open();
Console.WriteLine( "The Access data is {0} ",connection.State);
OleDbCommand command=connection.CreateCommand();
command.CommandText=sql;
OleDbDataReader reader=command.ExecuteReader();
while(reader.Read())
{
Console.WriteLine( "\t{0}\t{1} ",reader[ "xuehao "],reader[ "score "]);
}
Console.WriteLine( "The data in \ "student.mdb\ " is read completely ");
reader.NextResult();
int num=reader.FieldCount;
for(int i=0;i <num;i++)
{
Console.WriteLine( "\t{0}\t{1} ",reader[ "xuehao "],reader[ "name "]);
}
Console.WriteLine( "The data in \ "score.mdb\ " is read completely ");
reader.Close();
}
写上string sql= "select xuehao,score from score;select num,xuehao,name from student ";这句之后,就一个数据库的内容也显示不了了,但单写任何一个都没问题
------解决方案--------------------reader.NextResult();
之后你还是要用
while(reader.Read())
{
}
来读取数据
即
reader.NextResult();
int num=reader.FieldCount;
for(int i=0;i <num;i++)
{
while(reader.Read())
{
Console.WriteLine( "\t{0}\t{1} ",reader[ "xuehao "],reader[ "name "]);
}
}
------解决方案--------------------up
------解决方案--------------------看MSDN