c# - Save multiple records from a database in a string -


i have table in db (record id same 1 student, increments 1 automatically different students):

id  | firstname | lastname | subject | grade | recordid | ----+-----------+----------+---------+-------+----------+  1  | john      | doe      | 1       |     | 1        |  1  | john      | doe      | 2       | b     | 1        |  3  | max       | smith    | 1       | c     | 2        | 

using c# want save data id = 1 string in format:

name: john doe details: 1a; 2b name: max smith details: 1c 

what i've done far is:

sqlcommand cmd = _connection.createcommand(); string res = null; cmd.commandtext = "select count(distinct recordid) table1"; int numb = convert.toint32(cmd.executescalar().tostring()); int currentrecord = 1;  (int = 0; < numb; i++) { cmd.commandtext = "select firstname, lastname table1 recordid="+currentrecord+";"; res += "name: " + cmd.executescalar().tostring() + "\n details: ";  cmd.commandtext = "select subject, grade table1 recordid="+currentrecord+";"; res += "details: " + cmd.executescalar().tostring() + "\n";  currentrecord++ } 

this saves first record in string, this

name: john details: 1 name: max details: 1 

though need save multiple rows , columns. please help!

change command text this...

cmd.commandtext = "select firstname+' '+lastname table1 recordid="+currentrecord;    cmd.commandtext = "select subject+grade table1 recordid="+currentrecord; 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -