简体   繁体   English

C#在DataGridView和数据库中添加新行(访问)

[英]C# Adding new rows in DataGridView and database (Access)

I am working on a billing form and i plan to do it in DataGridView to display the Item Name, Quantity, Price, etc. In addition to that, I also intend to add button controls such as snacks and drinks, which would automatically add rows into the DataGridView when selected. 我正在处理一个帐单,我打算在DataGridView中显示项目名称,数量,价格等。除此之外,我还打算添加按钮控件,例如小吃和饮料,它们会自动添加行选中后进入DataGridView。 My DataGridView is binded to a DataSource. 我的DataGridView绑定到一个数据源。 My question is, how do i go about achieving (a) Automatically adding rows into DataGridView after selecting a Beverage from any Beverage button and (b) Inserting these records into the database as well. 我的问题是,我该如何实现(a)从任何“饮料”按钮选择“饮料”后自动将行添加到DataGridView中,以及(b)将这些记录也插入数据库中。 Any sort of guidance will be greatly appreciated, cheers! 任何形式的指导将不胜感激,加油! :) :)

Create a Datatable dynamically make it as datasource 动态创建一个数据表,使其成为数据源

Check this link for creating datatable dynamically 检查此链接以动态创建数据表

after creating it add 创建后添加

datagrid.DataSource=dt;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM