c# - Adding Column to populated DataSet -


i'm trying add column dataset has sql table data. wanted add column after data loaded keep track of values in database , values new in datagrid. can know rows add database. appreciate help.

here code, i'm trying column show @ point, worry updating rows new column later.

        sqlcom.commandtext = @"insert members (firstname, lastname) values ('" + textbox1.text +"', '"+ textbox2.text +"')";         sqlcom.executenonquery();          sqldataadapter sqladapt = new sqldataadapter("select * members", thisconnect);         dataset ds = new dataset();         sqladapt.fill(ds, "members");          //add column dataset?         ds.tables["members"].columns.add("indb");          datagridview1.datasource = ds;         datagridview1.datamember = "members";          thisconnect.close(); 

try this,

ds.tables["members"].columns.add(new datacolumn("indb", typeof(boolean)));

another option return field in select statement,

select *, cast(1 bit) indb member,

which sets true values returned table.

you should consider sql parameters avoid sql injections, example lets enter -','-');truncate table members; in first textbox delete rows members table no option retrieve data back

sqlcom.commandtext = @"insert members (firstname, lastname)                         values (@first,@last)"; sqlcom.parameters.addwithvalue("@first",textbox1.text); sqlcom.parameters.addwithvalue("@last",textbox2.text); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -