Click here to Skip to main content
16,019,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this datagridview whose rows are manually added on a click of a button..and i inherit a class to it's column to make it's cell datatimepicker.i need to insert it into the database without the need to retrieve it first from the database

What I have tried:

to insert it row by row by command excutenonquery
Posted
Updated 8-Sep-16 9:46am
Comments
[no name] 8-Sep-16 14:40pm    
Nothing you wrote after "button" makes any sense. Can you reword your posting to clearly describe a problem, ask a question and show the code you wrote that demonstrates your problem?
Karthik_Mahalingam 9-Sep-16 0:56am    
post the code.

If I understand the question correctly, you could
- Instead of populating a datatable from the database, define a data table having the desired structure that matches your datagridview (and your actual table)
- bind the datatable to the datagridview
- make modifications to the datatable (by the user)
- use OleDbDataAdapter to reflect the changes from the datatable to the Access database.

Have a look at following article: How to: Bind Data to the Windows Forms DataGridView Control[^] It uses Sql Server classes such as SqlCommand or SqlConnection but you would probably use OleDbCommand and OleDbConnection etc instead. Otherwise this should get you started.
 
Share this answer
 
Comments
Maciej Los 8-Sep-16 15:44pm    
Good suggestion. 5ed!
newcoder1 8-Sep-16 17:59pm    
your solution wont work in my case
because if i bind the datatable to the datagridview then i can't use any control that i inherit to the datagridview
Wendelius 8-Sep-16 23:24pm    
Not quite sure what you mean. Can you post example code
Wendelius 8-Sep-16 23:39pm    
As additional info, here's an example how to use custom column with datagridview. This shouldn't affect data binding How to: Host Controls in Windows Forms DataGridView Cells[^]
newcoder1 9-Sep-16 6:25am    
ok mika here's the thing
i'll make table
then i fill it with schema from the database
then i'll bind it to the datagridview datagridview.datasource=table
so after binding>>>if i want to add new row to the datagridview by code i wont be able
i will not be able to use such code( datagridview.rows.add)
instead it will be bindingsource code
so it will be like bindingsource.addnew()

and that is the problem when i use bindingsource.addnew()it will not add the custom datagridview coulmns

it will add just normal row which will appear in the datagridview since it's binding to the datatable

got it?

try it your self
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900