Adding new row to datagrid

V

vbtrying

Is it possible to add a new row programmatically to a datagrid, then store
the new row data to the database? My app needs to prompt the user to add a
new row - fill in the required fields in the datagrid - then store that data
to the database.

Thanks
 
S

Som Nath Shukla

yes its possible
there is property called allownewrow make it true.

and then write a update command.suppose ur using a dataapater
sqldataadapte da=new sqldataadapte ("select* from table ", conn);
datatable dt=new datatable();
da.Fill(dt);
datagrid.source=dt;

sqlcommandbuilder cbd=new sqlcommandbuilder(da);

da.update(dt);
Note:- if there is primary key in the table and u are accessing that primary
key in select command .then u can use sqlcommandbuilderwhich will
automatically generate the updtae insert and delete command.
if there is no primary key in table then u need to write ur own update
command.
 
V

vbtrying

Thank you very much for your input ...


Som Nath Shukla said:
yes its possible
there is property called allownewrow make it true.

and then write a update command.suppose ur using a dataapater
sqldataadapte da=new sqldataadapte ("select* from table ", conn);
datatable dt=new datatable();
da.Fill(dt);
datagrid.source=dt;

sqlcommandbuilder cbd=new sqlcommandbuilder(da);

da.update(dt);
Note:- if there is primary key in the table and u are accessing that primary
key in select command .then u can use sqlcommandbuilderwhich will
automatically generate the updtae insert and delete command.
if there is no primary key in table then u need to write ur own update
command.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top