c# - How can I add extra column in datagridview when I fetch data from database -
in database have 4 column. fetch database value in datagridview. want add 2 columns in datagridview. so, want make datagridview 6 columns. within 6 columns 4 columns filled database value. how can this?
oledbconnection con = new oledbconnection("connection string"); con.open(); datatable dtusers = new datatable(); oledbcommand cmd = new oledbcommand("select code,description,qnty,rate purchasetable'", con); oledbdataadapter da = new oledbdataadapter(cmd); da.fill(dtusers); datagridview1.datasource = dtusers; datagridview1.columns[0].name = "code "; datagridview1.columns[1].name = "description"; datagridview1.columns[2].name = "qnty"; datagridview1.columns[3].name = "rate"; con.close();
here 4 columns. code,description,qnty,rate. want add 2 more columns in datagridview. amount , narration. amount , narration columns not present in purchasetable.how can this?
if want blank columns create them , insert. if data in database add join query retrieve data.
adding blank columns
datagridview dgv = new datagridview(); dgv.datasource = dtusers; datagridviewcolumn amount = new datagridviewcolumn(); amount.headertext = "amount"; amount.name = "amount"; dgv.columns.insert(0, amount); datagridviewcolumn narration = new datagridviewcolumn(); narration.headertext = "narration"; narration.name = "narration"; dgv.columns.insert(0, narration);
Comments
Post a Comment