Hi,
I am developing a webApp that will take data from an Excel workbook and store the info in the database.
MY problem is that, the Excel data is structured in the following way :
Category | Course | Topics
Now for one category, there can be many courses and each course can have many topics.
So its a 1:Many relationship between each of those columns.
Now here is an Example :
Category | Course | Topics
Cat 1 Course1 Topic1
Topic2
Topic3
Topic4
Topic4
Cat 2 Course2 Topic1
Topic2
.
.
.
.
.
.
.
.
ETC/.....
So how can I write a code or use some method of the DataTable which will read all the Courses that belong to one particular category ? Or all the topics in one particular course ?
Loading

Kirtan PatelRank #292 · 8.6K reputationPosted Oct 16, 2009, 12:06 AM EDT
Here are many techniques shown by Microsoft to achieve the result you want
http://support.microsoft.com/kb/321686
All the Best :)
sandeep ram22 reputationPosted Oct 16, 2009, 1:10 AM EDT
Thanks for the reply.
I know how to access Excel files to load data into the database. What I am asking is , how to develop a logic that can extract only the associated topics for a particular course.
Ex - I need to develop an algorithm to get only those topic that belong to the Course 1 ...etc
jingeRank #2,527 · 554 reputationPosted Oct 16, 2009, 1:34 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 16, 2009, 1:41 AM EDT
Here is Logic you wanted to know (Code is Showing Just logic )
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
// Assume thaat you have data From Excel to DataTable
DataRow[] drCollection = dt.Select("Enter your Query Here");
//Do whatever you want to Do With Filtered Rows
foreach (DataRow r in drCollection)
{
string value1 = r[0].ToString();
string value2 = r[1].ToString();
// Code For inserting those Values into databse
}
}
sandeep ram22 reputationPosted Oct 16, 2009, 3:30 AM EDT
Just wondering how you can use LINQ in the select method ?
jingeRank #2,527 · 554 reputationPosted Oct 16, 2009, 3:41 AM EDT
DataTable dt = new DataTable(); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Age", typeof(int)); dt.Rows.Add("AA", 22); dt.Rows.Add("BB", 33);var query = from row in dt.AsEnumerable() where row.Field("Age") == 33 select row;Kirtan PatelRank #292 · 8.6K reputationPosted Oct 16, 2009, 3:42 AM EDT
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable() ;
var query = from c in dt.AsEnumerable() select new { Week = c.Field<string>("Week"), Person = c.Field<string>("Person"), Actual = c.Field<string>("Actual") };
dataGridView1.datasource = query;
}
friend,
please mark "do you like this answer" if my answer helped you
jingeRank #2,527 · 554 reputationPosted Oct 16, 2009, 3:43 AM EDT
sandeep ram22 reputationPosted Oct 16, 2009, 3:48 AM EDT
jingeRank #2,527 · 554 reputationPosted Oct 16, 2009, 4:02 AM EDT
sandeep ram22 reputationPosted Oct 22, 2009, 8:50 PM EDT
thanks for all the help, I have got the data into the database now - I am using LINQ statements instead of passing data through a BO.
Now my problem is that, the excel file contains about 6 categories,42 courses and some 845 topics in total. So thats 845 rows in total. And its taking about 20sec to upload this file to the database.
Thats too long. How can I reduce the time lapse here ?