关于数组的c#错误(对象引用未设置为对象的实例。)

时间:2014-12-07 21:16:55

标签: c# arrays

错误图片http://i.stack.imgur.com/AC5sE.png

我想向dataz添加数据但在构建时发现错误

这是我的代码

int i = 0;
string[][,] dataz = null;
conn.Open();

OleDbCommand db = conn.CreateCommand();
db.CommandType = CommandType.Text;
db.CommandText = "select name,img from [building] order by id asc ";

OleDbDataReader oReader = db.ExecuteReader();


while (oReader.Read())
{

        string name = oReader.GetString(0);
        string img = oReader.GetString(1);
        dataz[i] = new string[,] { { "name", name }, { "img", img } };
        i++;

}
conn.Close();

1 个答案:

答案 0 :(得分:-2)

使用Linq To SQL

var data = 
    ctx.Buildings.OrderBy(x => x.id).Select(x => new { x.name, x.img }).ToArray();