Oracle database multiple row -> c# -
how retrieve multiple data rows oracle database using c#.net? , disply data rows list-box.
let's brush code:
// extract methods, don't cram in onclick private void feedfriendslistbox() { string oracledb = @"connection string"; //done: wrap idisposable using using (oracleconnection conn = new oracleconnection(oracledb)) { conn.open(); //done: make sql readable - format out , use names parameter(s) string sql = @"select name, address friends age = :prm _age"; //done: wrap idisposable using using (oraclecommand cmd = new oraclecommand(sql, conn)) { cmd.parameters.add(new oracleparameter(txtlist.text, oracledbtype.decimal)); //done: wrap idisposable using using (var reader = cmd.executereader()) { if (!reader.hasrows) { listbox1.text = "not found"; messagebox.show("data not found", "not found", messageboxbuttons.ok, messageboxicon.information); return; } //done: value 0 based //done: use formatting (string interpolation), not concatenating while (reader.read()) listbox1.items.add($"{reader.getvalue(0)} {reader.getvalue(1)}"); } } } }
then use extracted method:
private void button2_click(object sender, eventargs e) { feedfriendslistbox(); }
Comments
Post a Comment