数据库访问的对象DataReader,包括SqlDataReader,OleDbDataReader等有个NextResult方法,返回一个布尔值,true。鼠标指到NextResult代码上显示这些东东:Advances the data reader to the next result , when reading the results of batch Transact-SQL statement . :)下面是个简单的例子。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace UseReader { public partial class Form1 : Form { public Form1() { InitializeComponent(); } privatevoid Form1_Load(object sender, EventArgs e) { SqlConnection cnn =new SqlConnection("data source=(local);initial catalog=tempdb;integrated security=sspi"); SqlCommand cmd =new SqlCommand("select status,displayname from mytable1;select * from mytable2", cnn); SqlDataReader reader =null; try { cnn.Open(); reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { listBox1.Items.Add(reader["displayname"]); } if (reader.NextResult()) { while (reader.Read()) { listBox2.Items.Add(reader["age"]); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { reader.Close(); } } } }
数据库访问的对象DataReader,包括SqlDataReader,OleDbDataReader等有个NextResult方法,返回一个布尔值,true。鼠标指到NextResult代码上显示这些东东:Advances the data reader to the next result , when reading the results of batch Transact-SQL...