How to return a single sql result to a string without using datatable (C #)?

I know how to populate a datatable using dAdapter.Fill (dTable) using System.Data.OleDb

But this is hard if I just want to get one string value, for example "select name from table where idperson = 1"

Can't I get around creating a DataTable?

I want to create the equivalent of the dlookup function in MS Access.

+3
source share
1 answer
using (var conn = new OleDbConnection(...))
using (var cmd = new OleDBCommand("select ...", conn)) {
   conn.Open();
   object result = cmd.ExecuteScalar(); // cast to appropriate type
   conn.Close();
}
+14
source

Source: https://habr.com/ru/post/1714911/


All Articles