Getting multiple records from SQL Server database with C# -
can tell me why not working, please? show me first database record matches statement , need display of them match. works except shows first record matches. thank in advance.
using (connection = new sqlconnection(connectionstring)) using (sqldataadapter adapter = new sqldataadapter("select * members month = '" + currentmonth + "' , day = '" + currentday +"'", connection)) { datatable memberstable = new datatable(); dataset info = new dataset(); adapter.fill(memberstable); adapter.fill(info); var rows = info.tables[0].rows; foreach (datarow row in rows) { nameemployee = info.tables[0].rows[0]["name"].tostring(); messagebox.show (nameemployee); } }
see following line:
nameemployee = info.tables[0].rows[0]["name"].tostring();
you within foreach loop , have "current" row in row variable. line should read:
nameemployee = row["name"].tostring();
Comments
Post a Comment