Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据从SQL Server加载到C#应用程序_Sql_Sql Server_C# 4.0 - Fatal编程技术网

将数据从SQL Server加载到C#应用程序

将数据从SQL Server加载到C#应用程序,sql,sql-server,c#-4.0,Sql,Sql Server,C# 4.0,我在通过C#应用程序从SQL Server数据库访问数据时遇到一些问题。我有一个小项目要做,我不能进一步,因为我的数据正在加载。我尝试将其加载到DataGridView中 以下是一些代码示例: public List<Country> GetCountryList() { string query = "SELECT * FROM Orszag", error = string.Empty; SqlDataReader rdr = ExecuteRea

我在通过C#应用程序从SQL Server数据库访问数据时遇到一些问题。我有一个小项目要做,我不能进一步,因为我的数据正在加载。我尝试将其加载到
DataGridView

以下是一些代码示例:

public List<Country> GetCountryList()
{
        string query = "SELECT * FROM Orszag", error = string.Empty;
        SqlDataReader rdr = ExecuteReader(query, ref error);

        List<Country> countryList = new List<Country>();
        if (error == "OK")
        {
            while (rdr.Read())
            {
                Country item = new Country();
                item.CountryId = Convert.ToInt32(rdr[0]);
                item.CountryName = rdr[1].ToString();
                countryList.Add(item);
            }
        }
        CloseDataReader(rdr);

        return countryList;
    }
这是连接字符串

protected string m_ConnectionString = "Data Source=SpD-PC;Initial Catalog=master;Integrated Security=SSPI";

您是否正在设置DataGridView的数据源

dgvGames.DataSource = CountryList;

我不明白实际的问题。“我不能再往前走了,因为我的数据正在加载”这意味着什么?你不能说这会导致什么异常或其他意外行为。问题是我的数据网格视图是空白的。。。。。我的数据没有出现……我猜,但我认为应该写为:“因为我的数据没有加载。”您如何连接到数据库?我没有看到SqlDataReader从中获取数据的任何连接。
protected string m_ConnectionString = "Data Source=SpD-PC;Initial Catalog=master;Integrated Security=SSPI";
dgvGames.DataSource = CountryList;