public ListMahasiswa GetListMahasiswa() { using var connection = new MySqlConnection(strconn); ListMahasiswa Res = new ListMahasiswa(); List <Mahasiswa> list = new List <Mahasiswa>(); try { connection.Open(); string strquery = "SELECT * FROM mahasiswa"; var commannd = new MySqlCommand(strquery, connection); var reader = commannd.ExecuteReader(); while (reader.Read()) { Mahasiswa mhs = new Mahasiswa(); mhs.nama = Convert.ToString(reader["Nama"]); mhs.nim = Convert.ToString(reader["NIM"]); mhs.asal = Convert.ToString(reader["Asal"]); mhs.datebirth = Convert.ToString(reader["Tanggal Lahir"]); list.Add(mhs); } Res.ErrorCode = "0"; Res.ErrorDesc = "Succes"; Res.mahasiswa = list; } catch (Exception e) { Res.ErrorCode = "1"; Res.ErrorDesc = e.Message.ToString(); throw; } return(Res); }
public override Task <ListMhs> GetListMahasiswa(empty request, ServerCallContext context) { ListMahasiswa Res = new ListMahasiswa(); List <Mahasiswa> mahasiswa = new List <Mahasiswa>(); Res = home.GetListMahasiswa(); foreach (var data in Res.mahasiswa) { Mahasiswa mhs = new Mahasiswa(); mhs.Nama = data.nama; mhs.Asal = data.asal; mhs.Nim = data.nim; mhs.Datebirth = data.datebirth; mahasiswa.Add(mhs); } var rslt = new ListMhs { Mahasiswa = { mahasiswa } }; return(Task.FromResult(rslt)); }