424,294 Members | 1,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,294 IT Pros & Developers. It's quick & easy.

Store datagridview values into a dataset

P: 12
Hi,

I want to store the values from the datagridview into a dataset and use the dataset as a method parameter.. However, the datagridview is not bind to any source..

I tried something like the one below but it won't work. Is there a way to do something like this?

DataSet ds = new DataSet();
ds = (DataSet) dgv.DataSource;

Thanks..
Oct 6 '08 #1
Share this Question
Share on Google+
5 Replies


nateraaaa
Expert 100+
P: 663
How are you loading data into your datagridview? Please post the code you are using.

Nathan
Oct 6 '08 #2

P: 12
How are you loading data into your datagridview? Please post the code you are using.

Nathan

The data are being entered manually by the user.. The datagridview only has 8columns/6rows, no more, no less.. The datagridview is used to get the calibration data from the user based on the actual readings from the calibration equipments.

Thanks....
-Jan
Oct 7 '08 #3

nateraaaa
Expert 100+
P: 663
The data are being entered manually by the user.. The datagridview only has 8columns/6rows, no more, no less.. The datagridview is used to get the calibration data from the user based on the actual readings from the calibration equipments.

Thanks....
-Jan
Sounds like you need to create a datatable and then programmatically create DataRows for your table based on the information entered by the user. You can then add the datatable to a dataset if you want or you could just reference the datatable directly.

Nathan
Oct 7 '08 #4

P: 12
Sounds like you need to create a datatable and then programmatically create DataRows for your table based on the information entered by the user. You can then add the datatable to a dataset if you want or you could just reference the datatable directly.

Nathan
I did something like this:

private DataTable _dtBLT = new DataTable();

Form_Load Event()
BindingSource bsBLT = new BindingSource();
for (int i = 0; i < 6; i++)
{
DataRow rowBLT = _dtBLT.NewRow();
_dtBLT.Rows.Add(rowBLT);
}
bsBLT.DataSource = _dtBLT;
dgvBLT.DataSource = bsBLT;

After the user entered the data in the datagridview, how will I store those values into the datatable? Can you provide some sample codes please?

Thanks.
Jan
Oct 8 '08 #5

nateraaaa
Expert 100+
P: 663
I did something like this:

private DataTable _dtBLT = new DataTable();

Form_Load Event()
BindingSource bsBLT = new BindingSource();
for (int i = 0; i < 6; i++)
{
DataRow rowBLT = _dtBLT.NewRow();
_dtBLT.Rows.Add(rowBLT);
}
bsBLT.DataSource = _dtBLT;
dgvBLT.DataSource = bsBLT;

After the user entered the data in the datagridview, how will I store those values into the datatable? Can you provide some sample codes please?

Thanks.
Jan
You are on the right track. You need to create DataColumns for _dtBLT. After you have done that you can create the datarow and then assign a value from the datagridview to each column in each row. Check out the link below for code examples:
http://www.eggheadcafe.com/community/aspnet/2/10044227/c--just-a-comment--bin.aspx

Nathan
Oct 9 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.