creating a database query METHOD

后端 未结 4 1675
旧巷少年郎
旧巷少年郎 2020-12-13 16:24

I\'m not sure if im delluded but what I would like to do is create a method that will return the results of a query, so that i can reuse the connection code. As i understand

4条回答
  •  情歌与酒
    2020-12-13 17:28

    Try ExecuteReader instead. It returns an object which can then be read like a file to get the results:

    OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
    while(myReader.Read()) 
    {
       Console.WriteLine(myReader.GetString(0));
    }
    

提交回复
热议问题