日期:2014-05-17  浏览次数:21278 次

在调用“Fill”前,SelectCommand 属性尚未初始化?
using (SqlConnection cnn = new SqlConnection())
                {
                    cnn.ConnectionString = DataLink.SqlConnectionString;
                    cnn.Open();
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.Connection = cnn;
                        cmd.CommandText = "";
                        cmd.CommandText += "SELECT UserName FROM Users" + Environment.NewLine;
                        cmd.CommandType = CommandType.Text;
                        DataSet ds = new DataSet();
                        SqlDataAdapter da = new SqlDataAdapter();
                        da.Fill(ds);
                        string user1 = ds.Tables[0].Rows[0].ToString();
                        string user2 = ds.Tables[1].Rows[0].ToString();
                        return true;
                    }
                }