Home > Software design >  Remove column name after get data
Remove column name after get data

Time:09-22

So when I get some string data from database I'm using this method

 var res = "";
  Future<void> cetak(String query) async {
    var req = await SqlConn.readData(query);
    setState(() {
      res = req;
    });
  }

then im using method cetak() like this

 cetak("SELECT CUST_NAME FROM ts_custxm WHERE CUST_CODE = '$custCode'");

But when im trying to display the res using Text(res) it show [{"CUST_NAME":"MY NAME"}]

any idea how to make res only show MY NAME without show its column name?

CodePudding user response:

You are getting result of a query in res variable. As a result of a query is an array of objects.

in your case : [{"CUST_NAME":"MY NAME"}]

so get MY NAME you should use res[0]["CUST_NAME"].

Hope this will help!

CodePudding user response:

You first need to convert by jsonDecode() or json.decode():

var req = jsonDecode(req)
setState(() {
    res = req;
});

and then access to your data by:

res[0]["CUST_NAME"].toString()
  • Related