15,887,329 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 14183767 (Top 45 by date)
Member 14183767
7-Jun-19 8:15am
View
Thank you!
Member 14183767
14-May-19 4:01am
View
hi , i am not sure where this dll is coming from , its not in my bin folder
Member 14183767
14-May-19 3:59am
View
hi i have this code
message.Subject = "username Recovery";
// Call Read before accessing data.
while (reader.Read())
{
var to = new MailAddress(reader["Email"].ToString());
message.To.Add(to);
}
// Passing values to smtp object
SmtpMail.Send(message);
Member 14183767
13-May-19 8:59am
View
hi , if i use my email address(work email) i am able to receive the email with username , but if i try using another email adr like the one from outlook it doesnt work
Member 14183767
3-May-19 3:52am
View
whats a trigger? and how to i use it?
Member 14183767
3-May-19 3:46am
View
the excel sheet is uploaded to data table then i use sql bulkcopy to insert it into my database table
Member 14183767
3-May-19 3:43am
View
hi this is for excel , the duplicates get inserted into the database table , they are not on the excel sheets
Member 14183767
3-May-19 2:51am
View
hi , how can i do that? can the data not be inserted into the datatable once only?
Member 14183767
2-May-19 8:10am
View
hi guys , i am also inserting excel sheet to db almost the same way as trunglb but i insert it into my database table, problem is the data is being inserted mutliple times casuing duplicates e.g. if my sheet has two rows of data then this is what will be inserted : ParentId Date Caption Filename User
record 1 record 1 record 1 record 1 record 1
record 2 record 2 record 2 record 2 record 2
record 1 record 1 record 1 record 1 record 1
record 2 record 2 record 2 record 2 record 2
Member 14183767
2-May-19 8:06am
View
can i not check the datatable to see if the data is there first before its inserted to database ?
Member 14183767
2-May-19 4:14am
View
Deleted
can i not check the datatable to see if the data is there first before its inserted to database ?
Member 14183767
30-Apr-19 10:45am
View
hi marciej , i managed to put the code together an it works , the problem is that it inserts the records from the excel sheets multiple times causing dupliacte records in my table, how can i prevent that ? like in the datatable? heres the snippet below: string ssqltable = "[dbo].[April]";
try{
string sConStr = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES';", sFileName);
DataTable dt = new DataTable();
SqlConnection sqlconn = new SqlConnection(strConnString);
sqlconn.Open();
using (OleDbConnection connection = new OleDbConnection(sConStr))
{
connection.Open();
dt = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
var sheets = dt.Rows[0].Field<string>("TABLE_NAME");
foreach(var sheet in sheets) //loop through the collection of sheets ;)
{
//your logic here...
string myexceldataquery = string.Format("Select * FROM [{0}]; ", sheets);
//get data
OleDbConnection oledbconn = new OleDbConnection(sConStr);
OleDbCommand oledbcmd = new OleDbCommand(myexceldataquery, oledbconn);
oledbconn.Open();
OleDbDataReader dr = oledbcmd.ExecuteReader();
{
//sql bulk copy here!
DataTable table = new DataTable("benlist");
table.Load(dr);
//set path
string CurrentFilePath = Path.GetFullPath(fuAttachment.PostedFile.FileName);
Session["filename"] = Path.GetFileNameWithoutExtension(CurrentFilePath);
SqlBulkCopy bulkcopy = new SqlBulkCopy(strConnString);
bulkcopy.DestinationTableName = ssqltable;
////Mapping Table column
bulkcopy.ColumnMappings.Add("IDNumber", "[IDNumber]");
bulkcopy.ColumnMappings.Add("DOB", "[DOB]");
bulkcopy.ColumnMappings.Add("BranchnameID", "[BranchnameID]");
bulkcopy.ColumnMappings.Add("BranchCode", "[BranchCode]");
bulkcopy.WriteToServer(table);
// }
connection.Close();
sqlconn.Close();
}
}
}
}
catch (Exception){}
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('File Uploaded');", true);
}
Member 14183767
30-Apr-19 9:18am
View
Deleted
hi marciej so i noticed on the line by line reading/compiling of the code that its picking up the sheet name even when i changed it :), my only problem is that im getting an error 'Exception:Thrown: "ExecuteReader requires an open and available Connection. The connection's current state is closed." i never closed the connection though. heres a snippet: public void up(string sFileName = @"filename")
{
string ssqltable = "[dbo].[PB_April_rejection]";
try{
string sConStr = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES';", sFileName);
DataTable dt = new DataTable();
SqlConnection sqlconn = new SqlConnection(strConnString);
sqlconn.Open();
using (OleDbConnection connection = new OleDbConnection(sConStr))
{
connection.Open();
dt = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
var sheets = dt.Rows[0].Field<string>("TABLE_NAME");
foreach(var sheet in sheets) //loop through the collection of sheets ;)
{
//your logic here...
string myexceldataquery = string.Format("Select * FROM [{0}]; ", sheets);
//get data
OleDbCommand oledbcmd = new OleDbCommand(myexceldataquery, connection);
OleDbDataReader dr = oledbcmd.ExecuteReader();
{
//sql bulk copy here!...
Member 14183767
23-Apr-19 10:02am
View
Hi , how can i fix 'OleDb SqlException: The Microsoft Access database engine cannot open or write to Excel file. It is already opened exclusively by another user, or you need permission to view and write its data.'
Member 14183767
23-Apr-19 4:01am
View
Many Thanks , it works
Member 14183767
23-Apr-19 4:00am
View
Hi Thank you it works! i had a bracket that was causing the syntax error
Member 14183767
23-Apr-19 3:22am
View
hi , i get the following error 'Syntax error in FROM clause.' and the number of rows in my sheets vary
Member 14183767
12-Apr-19 9:00am
View
hi thanks , i tried that first , i got an error saying 'syntax error in from clause'
Member 14183767
12-Apr-19 5:52am
View
hi , is there a way to get workbook name and store it in a db table?
Member 14183767
11-Apr-19 7:11am
View
the data import from excel is done on a separate page, then its redirected the another page where i have my gridview
Member 14183767
11-Apr-19 6:47am
View
yes BenReport is a stored procedure that i want to display on gridview
Member 14183767
11-Apr-19 6:19am
View
is there no way i can clear my tables/gridview before a new sheet is uploaded and the stored procedure is called?
Member 14183767
11-Apr-19 5:57am
View
hi i added the try catch block, the gridview is still showing the old data
Member 14183767
11-Apr-19 5:23am
View
hi thanks for ur input , my gridview is empty , but the tables have data
Member 14183767
11-Apr-19 2:34am
View
alright thank you
Member 14183767
10-Apr-19 7:47am
View
hey Maciej thanks for the changes , i implemented the code along with a try catch block it doesn't insert and i don't even get an error
Member 14183767
9-Apr-19 6:14am
View
i am confused Maciej, the loop checks for the sheet and then the sqlbulkcopy will copy all the data from the sheet in the loop. meaning i no longer need to specify string myexceldataquery?
Member 14183767
9-Apr-19 3:36am
View
hi , does this mean i no longer need this line of code : string myexceldataquery = "Select * FROM [$] ";?
Member 14183767
9-Apr-19 3:34am
View
Deleted
hi , does this mean i no longer need this line of code : string myexceldataquery = "Select * FROM [$] ";?
Member 14183767
4-Apr-19 2:35am
View
what do i put in this line of code: string myexceldataquery = "Select * FROM [$] "; ?
Member 14183767
3-Apr-19 11:38am
View
thank you MadMyche it works!!!!
Member 14183767
3-Apr-19 11:31am
View
it exists i just checked
Member 14183767
3-Apr-19 11:19am
View
"An exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll but was not handled in user code" Additional info 'Department'
Member 14183767
3-Apr-19 11:17am
View
i fixed that it throws an error on this code : if(rd["Departmet"].ToString() == "EPIP")
Member 14183767
3-Apr-19 11:13am
View
Department
Member 14183767
3-Apr-19 11:08am
View
i understand now what its doing thanks for that! but issue is that even when ive used ur solution i still get an error which is confusing me, plz help i am still learning
Member 14183767
3-Apr-19 11:02am
View
its still giving me the same error , this is my login page, i would like for the code to check what department is in PB_Register for each user and redirect to appropriate page
Member 14183767
3-Apr-19 10:36am
View
Deleted
i
Member 14183767
3-Apr-19 10:22am
View
it doesnt work , i get an error "An exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll but was not handled in user code" also rd seems to be casted as an integer
Member 14183767
3-Apr-19 10:00am
View
it doesnt work , how do i use the value from database table
Member 14183767
2-Apr-19 10:34am
View
yes
Member 14183767
1-Apr-19 3:41am
View
Hi , if i implement your solution it only shows one record
Member 14183767
1-Apr-19 3:19am
View
yes i have a break point on page load that helps me debug line by line, both BenReport and spTest skip the first row in the table
Member 14183767
18-Mar-19 7:49am
View
Deleted
hi i have tried the following code , it only renames one sheet and then i get an error 'worksheet out of range' on package.Workbook.Worksheets[2].Name =""
//package.Workbook.Worksheets[1].Name = "Bencount";
//package.Workbook.Worksheets[2].Name = "BeneficiariestobeExctracted";
////package.Workbook.Worksheets[3].Name = "benificiarieswithnoAccNo";
////package.Workbook.Worksheets[4].Name = "account number>11 characters/wages<100";
////package.Workbook.Worksheets[5].Name = "beneficiary appear on more than project";
////package.Workbook.Worksheets[6].Name = "Duplications by account number";
////package.Workbook.Worksheets[7].Name = "Check Missing Beneficiaries";
////package.Workbook.Worksheets[2].Name = "TotalWages";
Member 14183767
15-Mar-19 11:18am
View
hi , thanks for ur response however i am using EFP PLUS and i have 9 sheets that i need to be renamed to a list of names that i chose, please help
Show More