小编mim*_*ckd的帖子

SqlCommand只返回一行

尝试只返回前几行,因为我的数据库太大了,但是当我测试我的SQL时,我做了一个select *并且只返回了第一行.

SqlCommand sqlCmd = new SqlCommand();
SqlDataReader reader;

sqlCmd.CommandText = "SELECT * FROM Log";
sqlCmd.CommandType = CommandType.Text;
sqlCmd.Connection = myConnection;

myConnection.Open();

reader = sqlCmd.ExecuteReader();

Log logs = null;

while (reader.Read())
{
    logs = new Log();
    logs.Id = Convert.ToInt32(reader.GetValue(0));
}

return logs;
myConnection.Close();
Run Code Online (Sandbox Code Playgroud)

我的解决方案有什么问题?

c# sql sql-server sqlcommand

2
推荐指数
1
解决办法
282
查看次数

标签 统计

c# ×1

sql ×1

sql-server ×1

sqlcommand ×1