I have table which contains order number and corresponding Serial number range for those order.
I need to create another table where I can store order number with a list of all serial numbers for that order.
Table I have:
Order No SerialNoStart SerialNoEnd
1 55 66
2 77 90
3 233 237
Table I need to generate from above table:
Order No SerialNumber
1 55
2 56
3 57
| |
| |
3 66
4 77
4 78
| |
| |
4 90
5 233
5 234
| |
| |
5 237
It would be great if anyone can show me how to get this done. I dont care if it's done using function, procedure, etc. whatever is easy.
Thanks.
Loading
Sam HobbsPosted Apr 16, 2011, 6:09 PM
I think one reason people are not replying is that it seems so extremely easy. Also, questions about how to write a program to do something are interpreted as a request for someone to do all the programming for them. Sometimes members are lucky and another member volunteers to do the programming but you are much more likely to get help it you have a specific question.
The following is written for a new console project. The technique would be the same or similar for a Windows Forms project. Try doing the following for the fun of it. You can use your input table for the following.
After creating a new console project, go to the Data Sources window and create a data source for your table. See my Database Table Update in a DataGridView without Writing Code for help with that.
After creating a data source, look in the Solution Explorer; there will be an item for the new Data Source, also called a DataSet. The name will have a "xsd" extension.
In your program, the first thing to do is to create an instance of the DataSet. To get the DataSet's name into your program, just start typing the name as shown in the Solution Explorer and intellisense will help you complete the name. My DataSet is called _C_SharpCornerDataSet so my line to create an instance of the DataSet is:
_C_SharpCornerDataSet ds = new _C_SharpCornerDataSet();
Next you need to create an instance of a TableAdapter for your table. TableAdapters exist in a TableAdapters namespace. The name is the DataSet's name prefixed with "TableAdapters". So for me the TableAdapters namespace name is _C_SharpCornerDataSetTableAdapters. The TableAdapter name for me is PeopleTableAdapter, so my line to create an instance of a TableAdapter is:
_C_SharpCornerDataSetTableAdapters.PeopleTableAdapter ta = new _C_SharpCornerDataSetTableAdapters.PeopleTableAdapter();
In the DataSet is a DataTable for your table. My table is called People but the name for you will be your table's name. You need to fill the DataTable, as in:
ta.Fill(ds.People);
Then all you need to do is to iterate over the rows, as in:
foreach (_C_SharpCornerDataSet.PeopleRow row in ds.People.Rows)
Console.WriteLine("{0} {1} {2}", row.Id, row.First, row.Last);
Note that the fields will be whatever fields are in your table; my table has the fields Id, First and Last but your table's fields will be your table's fields. Try doing this much and then get back to me with the results. Let me know if you have questions; I will use the above material for an article in the future for this web site.
Suthish NairPosted Apr 16, 2011, 12:44 AM
P GPosted Apr 15, 2011, 1:57 PM