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
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shaik Vahid
1.6k
124
5.7k
import .xls file to mysql database
Jan 2 2018 12:08 AM
protected void btnExcel_Click(object sender, EventArgs e)
{
string connString = "";
string strFileType = Path.GetExtension(FileUpload1.FileName).ToLower();
string path =Server.MapPath(FileUpload1.PostedFile.FileName);
//Connection String to Excel Workbook
if (strFileType.Trim() == ".xls")
{
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
}
else if (strFileType.Trim() == ".xlsx")
{
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
}
// FileUpload1.SaveAs(Server.MapPath(FileUpload1.FileName));
string query = "SELECT * FROM [UserDetails]";
OleDbConnection conn = new OleDbConnection(connString);
if (conn.State == ConnectionState.Closed)
conn.Open();
OleDbCommand cmd = new OleDbCommand(query, conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
// string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
// dt=objBLHR.Read_Sheet(filename);
gd1.DataSource = ds.Tables[0];
gd1.DataBind();
}
}
How to avoid this error from the page.
Reply
Answers (
5
)
Identity server in asp.net mvc
Model popup is not showing in my grid column in asp.net?