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
Geet Priyadarshini
NA
57
9k
Getting an error while using OracleBulkCopy
Mar 22 2018 1:01 AM
CS0029: Cannot implicitly convert type 'System.Data.OleDb.OleDbTransaction' to 'System.Data.OracleClient.OracleTransaction' is the error which I'm getting in my code.
I'm using ASP.NET and C#
The aspx code is
private
void
InsertCSVRecords(DataTable dt)
{
conn.Open();
using
(OracleTransaction OracleTransaction =conn.BeginTransaction())
{
using
(OracleBulkCopy OracleBulkCopy =
new
OracleBulkCopy(objConnection, OracleBulkCopyOptions.Default, OracleTransaction))
{
//assigning Destination table name
OracleBulkCopy.DestinationTableName =
"material_master"
;
//Mapping Table column
OracleTransaction.ColumnMappings.Add(
"req_no"
,
"req_no"
);
OracleTransaction.ColumnMappings.Add(
"req_dt"
,
"req_dt"
);
OracleTransaction.ColumnMappings.Add(
"req_by"
,
"req_by"
);
OracleTransaction.ColumnMappings.Add(
"mat_desc"
,
"mat_desc"
);
OracleTransaction.ColumnMappings.Add(
"mat_type_cd"
,
"mat-type_cd"
);
OracleTransaction.ColumnMappings.Add(
"base_uom_cd"
,
"base_uom_cd"
);
OracleTransaction.ColumnMappings.Add(
"stor_loc_cd"
,
"stor_loc_cd"
);
OracleTransaction.ColumnMappings.Add(
"pur_grp_cd"
,
"pur_grp_cd"
);
OracleTransaction.ColumnMappings.Add(
"hsn_cd"
,
"hsn_cd"
);
OracleTransaction.ColumnMappings.Add(
"mat_long_desc"
,
"mat_long_desc"
);
OracleTransaction.ColumnMappings.Add(
"tax_ind"
,
"tax_ind"
);
OracleTransaction.ColumnMappings.Add(
"active_ind"
,
"active_ind"
);
OracleTransaction.ColumnMappings.Add(
"del_ind"
,
"del_ind"
);
//inserting Datatable Records to DataBase
OracleTransaction.WriteToServer(dt);
OracleTransaction.Commit();
conn.Close();
}
}
}
protected
void
Import_Click(
object
sender, EventArgs e)
{
try
{
//Upload and save the file
string
csvPath = Server.MapPath(
"~/Uploads/"
) + Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(csvPath);
if
((FileUpload1.PostedFile !=
null
) && (FileUpload1.PostedFile.ContentLength > 0))
{
string
fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
string
SaveLocation = Server.MapPath(
"Uploads"
) +
"\\"
+ fn;
FileUpload1.PostedFile.SaveAs(SaveLocation);
Response.Write(
"The file has been uploaded."
);
DataTable dt =
new
DataTable();
DataSet ds =
new
DataSet();
dt.Columns.AddRange(
new
DataColumn[14] {
new
DataColumn(
"req_no"
,
typeof
(
string
)),
new
DataColumn(
"req_dt"
,
typeof
(
string
)),
new
DataColumn(
"req_by"
,
typeof
(
string
)),
new
DataColumn(
"mat_cd"
,
typeof
(
string
)),
new
DataColumn(
"mat_desc"
,
typeof
(
string
)),
new
DataColumn(
"mat_type_cd"
,
typeof
(
string
)),
new
DataColumn(
"base_uom_cd"
,
typeof
(
string
)),
new
DataColumn(
"stor_loc_cd"
,
typeof
(
string
)),
new
DataColumn(
"pur_grp_cd"
,
typeof
(
string
)),
new
DataColumn(
"hsn_cd"
,
typeof
(
string
)),
new
DataColumn(
"mat_long_desc"
,
typeof
(
string
)),
new
DataColumn(
"tax_ind"
,
typeof
(
string
)),
new
DataColumn(
"active_ind"
,
typeof
(
string
)),
new
DataColumn(
"del_ind"
,
typeof
(
string
))});
//Read the contents of CSV file.
string
csvData = File.ReadAllText(fn);
// Execute a loop over the rows.
foreach
(
string
row
in
csvData.Split(
'\n'
))
{
if
(!
string
.IsNullOrEmpty(row))
{
dt.Rows.Add();
int
i = 0;
//Execute a loop over the columns.
foreach
(
string
cell
in
row.Split(
','
))
{
dt.Rows[dt.Rows.Count - 1][i] = cell;
i++;
}
}
}
//Bind the DataTable.
GridView1.DataSource = dt;
GridView1.DataBind();
InsertCSVRecords(dt);
}
else
{
Response.Write(
"Please select a file to upload."
);
}
}
catch
(Exception ex)
{
Response.Write(ex.Message);
}
}
Reply
Answers (
0
)
How to Read .XLSB file using ExcelReaderFactory
Exception handling query