on 06-15-2020 3:39 PM
Hi Experts,
I want to import excel sheet directly into an internal table in the hana schema of sap hana 1.0 that is used by SAP Business One 9.3 For Hana. The excel sheet consists of some data. There is only one sheet and have 20 columns.
The excel sheet is exported from mysql using an application that developed by using vb.net of vs. 2015 or 2010 and then import it to hana schema table. The table name is Invoice_AR in hana schema and in mysql schema.
When the importing take places, the system prompts error. The screen shot of error message as follows:
I have created same column types between mysql schema table and hana schema table. I didn't use double in mysql schema table fields. I also don't use column type 'system.init32'.
Is there any change during the Importing of excel data in the system?
This is the code I am using:
Private Sub ImportToHana(FullFileName As String)
Dim filenam As String
filenam = FullFileName
Dim ExcelConnection As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filenam + " ;Extended Properties=""Excel 12.0 Xml;HDR=Yes""")
ExcelConnection.Open()
Dim expr As String = "SELECT * FROM [Sheet1$]"
Dim objCmdSelect As OleDbCommand = New OleDbCommand(expr, ExcelConnection)
Dim objDR As OleDbDataReader
Dim SQLconn As New HanaConnection()
Dim sConn As String = ""
sConn = "Server=" & sSAPServerName & _
";Current Schema =" & sSAPDbName & _
";UseTrusted=False" & _
";UserID=" & sSAPDbUserName & _
";Password=" & sSAPDbPassword
SQLconn.ConnectionString = sConn
SQLconn.Open()
Using bulkCopy As HanaBulkCopy = New HanaBulkCopy(SQLconn)
bulkCopy.DestinationTableName = "AR_Invoice"
Try
objDR = objCmdSelect.ExecuteReader
bulkCopy.WriteToServer(objDR)
objDR.Close()
SQLconn.Close()
MsgBox("Data's are imported to SQL Succesfully", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Using
End Sub
Please help to solve this issue.
Thanks in advance.
Rgds,
Steve
Hi Steve,
you can drop hanabulkcopy and use other method instead.
You can try to use this sample (it is in C#):
using System.IO;
using System.Data;
using System.Data.OleDb;
using System.Data.HanaClient;
using System.Configuration;
protected void Upload(object sender, EventArgs e)
{
//Upload and save the file
string excelPath = Server.MapPath("~/Files/") +
Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(excelPath);
string conString = string.Empty;
string extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
switch (extension)
{
case ".xls": //Excel 97-03
conString = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
break;
case ".xlsx": //Excel 07 or higher
conString =
ConfigurationManager.ConnectionStrings["Excel07+ConString"].ConnectionString;
break;
}
conString = string.Format(conString, excelPath);
using (OleDbConnection excel_con = new OleDbConnection(conString))
{
excel_con.Open();
string sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
null).Rows[0]["TABLE_NAME"].ToString();
DataTable dtExlData= new DataTable();
//[OPTIONAL]: It is recommended as otherwise the data will be considered
as String by default.
dtExlData.Columns.AddRange(new DataColumn[3] { new DataColumn("Id",
typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Salary",typeof(decimal)) });
using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" +
sheet1 + "]", excel_con))
{
oda.Fill(dtExlData);
}
excel_con.Close();
string consString =
ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (HanaConnection con = new HanaConnection(consString))
{
using (HanaBulkCopy HanaBulkCopy = new HanaBulkCopy(con))
{
//Set the database table name
HanaBulkCopy.DestinationTableName = "dbo.AR_Invoice";
//[OPTIONAL]: Map the Excel columns with that of the database table
HanaBulkCopyColumnMappings.Equal("EntryId", "EntryId");
HanaBulkCopyColumnMappings.Equal("CardCode", "CardCode");
HanaBulkCopyColumnMappings.AddEqualPriceTotal", "PriceTotal");
con.Open();
HanaBulkCopy.WriteToServer(dtExlData);
con.Close();
}
}
}
}
Good luck
Rgds,
Jimmy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
8 | |
6 | |
6 | |
5 | |
4 | |
2 | |
2 | |
2 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.