TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Upload a Excel file in Oracle Database Using asp.net
Viraj Deshmukh
Feb 26
2015
Code
9.6
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
ASPX Page
<table>
<tr>
<td>
<asp:FileUpload ID=
"fUpload"
runat=
"server"
/>
</td>
</tr>
<tr>
<td>
<asp:Button ID=
"btnUpload"
runat=
"server"
Text=
"Upload Excel"
onclick=
"btnUpload_Click"
/>
</td>
</tr>
</table>
.CS File
protected
void
btnUpload_Click(
object
sender, EventArgs e)
{
try
{
if
(fUpload.HasFile)
{
string
Path = Server.MapPath(fUpload.FileName);
FillDatasetExcel(Path);
}
}
catch
(Exception ex)
{
throw
ex;
}
}
public
DataTable FillDatasetExcel(
string
filepath)
{
string
path = filepath;
// Prepare cnnection string
string
connectionstring =
@
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
+ path +
";Extended Properties='Excel 12.0 Xml;HDR=YES;FMT=Delimited';"
;
byte
[] Bytes = fUpload.FileBytes;
File.WriteAllBytes(path, Bytes);
OleDbConnection connection =
new
OleDbConnection();
connection.ConnectionString = connectionstring;
OleDbCommand command =
new
OleDbCommand();
command.CommandType = CommandType.Text;
command.Connection = connection;
command.CommandText =
"Select * FROM [Sheet1$]"
;
connection.Open();
// create data table object
DataTable dt =
new
DataTable();
// Execute Reader and load the data into datatable
dt.Load(command.ExecuteReader());
// Close the connection
connection.Close();
return
dt;
}
}
Oracle Database
Excel