显示Enumeration的SqlDataReader没有产生任何结果

时间:2016-11-16 12:36:00

标签: c# sqldatareader sqlconnection sqlcommand

我正在尝试使用SqlDataReader读取数据。

但在执行此代码时,读者显示“枚举没有产生任何结果”。

 string connetionString = null;
            SqlConnection cnn;
            SqlCommand cmd;
            string sql = null;
            SqlDataReader reader;

            connetionString = "Data Source=INBAGHPC00840;Initial Catalog=Testing;Persist Security Info=True;User ID=sa;Password=12345";
            sql = "select * from [Category]";

            cnn = new SqlConnection(connetionString);
            try
            {
                cnn.Open();
                cmd = new SqlCommand(sql, cnn);
                reader = cmd.ExecuteReader();
                while (reader.Read()) //Here reader shows : Enumeration yielded no results
                {


                  // MessageBox.Show(reader.GetValue(0) + " - " + reader.GetValue(1) + " - " + reader.GetValue(2));
                }
                reader.Close();
                cmd.Dispose();
                cnn.Close();
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Can not open connection ! ");
            }

我无法理解我在这里失踪的东西。请让我知道..

0 个答案:

没有答案