Subscribe to Subscribers

Forums » .NET » .NET »

How to search and get the values from excel sheet....


Posted Date: 19 Jun 2012      Posted By:: Lawrence     Member Level: Gold    Member Rank: 321     Points: 5   Responses: 2



Hi Everyone,
Good Morning to all,
I maintained student attendance morning and evening list.... If i saved database there is lots of space occured...so i maintained in excel sheet for each class in my Asp.net solution directory.....

Now if i select any class from dropdownlist then show the attendance details by excel sheet or gridview and if i select particular student form dropdownlist then i want to show the particular student attendance details by excel sheet or gridview. How to do.... Just tell the solution...

In gridview Example:

Name Morning Evening

Lawrence Present Absent

I want to show like that..... In Excel it shows noraml form.....



Thanks In Advanced




Responses

#676346    Author: Ajatshatru Upadhyay      Member Level: Gold      Member Rank: 17     Date: 19/Jun/2012   Rating: 2 out of 52 out of 5     Points: 2

Hi,

Below link may help you:
http://msdn.microsoft.com/en-us/library/e4x1k99a(VS.80).aspx

Btw, retrieving data from excel is a bit complex and time consuming process. So I would suggest you to use Access database instead of Excel file, if you don't want to use SQL database.
You can also use xml file for the same purpose.

Hope it'll help you.
Regards
Ajatshatru


 
#676473    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 20/Jun/2012   Rating: 2 out of 52 out of 5     Points: 4

Refer below sample example i worked it and test it also

Excel data look like this

Sno Sname Class
101 John 1std
102 Mike 1std
103 Sekar 2nd
104 Mathew 3rd


Client side

Select Class<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>1std</asp:ListItem>
<asp:ListItem>2nd</asp:ListItem>
<asp:ListItem>3rd</asp:ListItem>
</asp:DropDownList>
<br />
Select Srudent Name<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<br />
<asp:Button runat="server" Text="Search" OnClick="Unnamed1_Click" /><br />
<asp:GridView runat="server" ID="gridview">
</asp:GridView>


Server side

using System.Data.OleDb;
using System.Data;
using System.Data.SqlClient;
public partial class ExcelSearch : System.Web.UI.Page
{
DataTable dt = new DataTable();
DataSet ds = new DataSet();
string path = @"D:\student.xlsx";
protected void Page_Load(object sender, EventArgs e)
{
//Initially load student name in the second dropdown list from excel sheet
if (!Page.IsPostBack)
{
OleDbConnection MyConnection = null;
DataSet DtSet = null;
OleDbDataAdapter MyCommand = null;
MyConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + path + "';Extended Properties=Excel 12.0;");
MyConnection.Open();
MyCommand = new OleDbDataAdapter("select Sname from [Sheet1$]", MyConnection);
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet, "[Sheet1$]");
DropDownList2.DataSource = DtSet;
DropDownList2.DataTextField = "Sname";
DropDownList2.DataValueField = "Sname";
DropDownList2.DataBind();
MyConnection.Close();
}
}
protected void Unnamed1_Click(object sender, EventArgs e)
{
try
{
string excelconstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + path + "';Extended Properties=Excel 12.0;";
OleDbConnection excelcon = new OleDbConnection(excelconstr);
OleDbCommand cmd = new OleDbCommand("Select * from [Sheet1$] where class='" + DropDownList1.Text + "' and Sname='" + DropDownList2.Text + "'", excelcon);
excelcon.Open();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dt);
gridview.DataSource = dt;
gridview.DataBind();
excelcon.Close();
}
catch (Exception ex)
{
}
}
}


Regards
N.Ravindran
Your Hard work never fails


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : How to develop a application for petrol bulk
Previous : Excel Chart X Axis Issue
Return to Discussion Forum
Post New Message
Category:

Related Messages

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.