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
Riddhi Valecha
441
3.3k
413.2k
Microsoft Office Access Database Engine error - URGENT
Oct 21 2014 4:56 AM
Hi all,
I am getting the error -
The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data.
-----
I want to update the excel sheet records to sql server table from front-end.
--
My method is-
--------------
#region ExcelSheetNames
private string[] GetExcelSheetNames(string excelFile)
{
OleDbConnection objConn = null;
System.Data.DataTable dt = null;
try
{
//String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
// "Data Source=" + excelFile + ";Extended Properties=Excel 8.0;";
String connString = ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString;
// Create connection object by using the preceding connection string.
objConn = new OleDbConnection(connString);
// Open connection with the database.
objConn.Open();
dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dt == null)
{
return null;
}
else
{
String[] excelSheets = new String[dt.Rows.Count];
int i = 0;
// Add the sheet name to the string array.
foreach (DataRow row in dt.Rows)
{
excelSheets[i] = row["TABLE_NAME"].ToString();
i++;
}
return excelSheets;
}
}
catch (Exception err) { err.Message.ToString(); return null; }
finally
{
// Clean up.
if (objConn != null)
{
objConn.Close();
objConn.Dispose();
}
if (dt != null)
{
dt.Dispose();
}
}
}
#endregion
#region GetExcelSheets
private void GetExcelSheets(string FilePath, string Extension, string isHDR)
{
try
{
System.Diagnostics.Process.Start("");
string conStr = String.Empty;
switch (Extension)
{
case ".xls": //Excel 97-03
conStr = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
break;
case ".xlsx": //Excel 07
conStr = ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString;
break;
}
//Get the Sheets in Excel WorkBoo
conStr = String.Format(conStr, FilePath, isHDR);
OleDbConnection connExcel = new OleDbConnection(conStr);
OleDbCommand cmdExcel = new OleDbCommand();
OleDbDataAdapter oda = new OleDbDataAdapter();
cmdExcel.Connection = connExcel;
connExcel.Open();
//ddl_excelsheets
ddl_excelsheets.Items.Clear();
//ddl_excelsheets.Items.Add(new ListItem("--Select Sheet--", ""));
//ddl_excelsheets.DataSource = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
//ddl_excelsheets.DataTextField = "tbl_AssetDetails";
//ddl_excelsheets.DataValueField = "tbl_AssetDetails";
//ddl_excelsheets.DataBind();
ddl_excelsheets.Items.Add(new ListItem("--Select Sheet--", ""));
ddl_excelsheets.DataSource = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
ddl_excelsheets.DataTextField = "TableName";
ddl_excelsheets.DataValueField = "TableName";
ddl_excelsheets.DataBind();
connExcel.Close();
}
catch (Exception err) { err.Message.ToString(); }
}
#endregion
----------
Please let me know where I am going wrong.
Reply
Answers (
0
)
c# datagridview cells multiplications with sum
access from drive and show it as link