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
sandeep ramPosted Oct 23, 2009, 12:50 AM
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 ?
jingePosted Oct 16, 2009, 8:02 AM
sandeep ramPosted Oct 16, 2009, 7:48 AM
jingePosted Oct 16, 2009, 7:43 AM
Kirtan PatelPosted Oct 16, 2009, 7:42 AM
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
jingePosted Oct 16, 2009, 7:41 AM
sandeep ramPosted Oct 16, 2009, 7:30 AM
Just wondering how you can use LINQ in the select method ?
Kirtan PatelPosted Oct 16, 2009, 5:41 AM
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
}
}
jingePosted Oct 16, 2009, 5:34 AM
sandeep ramPosted Oct 16, 2009, 5:10 AM
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
Kirtan PatelPosted Oct 16, 2009, 4:06 AM
Here are many techniques shown by Microsoft to achieve the result you want
http://support.microsoft.com/kb/321686
All the Best :)