public IActionResult Get() { //string[] data = { }; string data = null; try { SqlConnection conn = konn.GetConn(); conn.Open(); SqlCommand cmd = new SqlCommand("select @@servername namaserver", conn); SqlDataReader da = cmd.ExecuteReader(); while (da.Read()) { data = (da["namaserver"]).ToString(); } da.Close(); conn.Close(); } catch (SqlException ex) { return(BadRequest(ex.Message)); } string [] dtarray = { data }; return(Ok(dtarray)); }
public Startup(IConfiguration configuration) { Configuration = configuration; Koneksi konn = new Koneksi(); konn.GetConn(); }
public IActionResult GetRekObject(string tahun) { getdb.GetDb(tahun); string nmdb = getdb.Nmdbsimda.TrimEnd(); IEnumerable <ParamRekObjekPen> dataVM = new List <ParamRekObjekPen>(); if (!String.IsNullOrEmpty(nmdb)) { try { SqlConnection conn = konn.GetConn(); conn.Open(); SqlCommand cmd = new SqlCommand(" USE " + nmdb + "" + " SELECT (substring(ltrim(rTRIM(A.Kd_Rek_1) + " + " rTRIM(A.kd_rek_2) + rTRIM(A.Kd_rek_3) + rTRIM(A.Kd_rek_4)), 1, 6)) kd_rek, " + " NM_REK_4 NM_REK FROM Ref_Rek_4 A " + " WHERE A.Kd_Rek_1 = 4 and A.KD_REK_2=1 AND A.KD_REK_3=1" + "", conn); cmd.ExecuteNonQuery(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); var table = (from DataRow dr in dt.Rows select new ParamRekObjekPen() { //Kd_rek_all = (dr["Kd_rek_all"]).ToString(), Kd_rek = (dr["Kd_rek"]).ToString().TrimEnd(), Nmrek = (dr["nm_rek"]).ToString().TrimEnd(), }).OrderBy(c => c.Kd_rek).ToList(); dataVM = table.ToList(); conn.Close(); } catch (SqlException ex) { return(BadRequest(ex.Message)); } } else { return(Ok("Data untuk Tahun " + tahun + " tidak ada")); } return(Ok(dataVM)); }