Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Upload a Excel file in Oracle Database Using asp.net
WhatsApp
Viraj Deshmukh
Feb 26
2015
10.3
k
0
0
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
Up Next
Upload a Excel file in Oracle Database Using asp.net