我正在创建用于将excel文件上传/导入ms动态CRM的Web应用程序。如果excel文件中只有一个实体,则此Web应用程序可以正常工作。但是,如果excel文件中有两个实体,则Web应用程序不会导入。
以下是我的代码:
#DEFINE ARRAY_SIZE 10
class HostObject {
//other member variables
vector<Object1> vec;
//default constructor
HostObject(){
vec.reserve(ARRAY_SIZE);
}
//my custom constructor
HostObject(double parmeter1, double parameter2, doubleparameter3) {
vec.reserve(ARRAY_SIZE);
//some code doing some calculations
for (int i = 0; i <ARRAY_SIZE; i++){
vec.push_back(Object1( double p1, int p2, double p3, intp4));
}
}
}
我的问题是如何将std::vector
用于两个实体。如上所示,我试图两次致电protected void btnOne_Click(object sender, EventArgs e)
{
Stopwatch st = new Stopwatch();
st.Start();
if (FileUpload1.HasFile)
{
string Filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string Extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
string Folderpath = ConfigurationManager.AppSettings["FolderPath"];
string Filepath = Server.MapPath(Folderpath + Filename);
FileUpload1.SaveAs(Filepath);
DataTable dt = ImportData(Filepath, Extension);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
try
{
Entity contractline = new Entity("new_contractline");
contractline["new_contractid"] = dt.Rows[i][1].ToString();
contractline["new_lineitem"] = dt.Rows[i][2].ToString();
Entity productitem = new Entity("new_productitem");
productitem["new_instanceid"] = dt.Rows[i][3].ToString();
productitem["new_productnumber"] = dt.Rows[i][4].ToString();
var multiplerequest = new ExecuteMultipleRequest()
{
Settings = new ExecuteMultipleSettings()
{
ContinueOnError = false,
ReturnResponses = true
},
Requests = new OrganizationRequestCollection()
};
CreateRequest createcontractline = new CreateRequest { Target = contractline };
CreateRequest createproductitem = new CreateRequest { Target = productitem };
multiplerequest.Requests.Add(createcontractline);
multiplerequest.Requests.Add(createproductitem);
ExecuteMultipleResponse multirespon = (ExecuteMultipleResponse)service.Execute(multiplerequest);
}
catch (Exception ex)
{
//Label1.Text = ex.Message;
}
}
st.Stop();
TimeSpan ts = st.Elapsed;
Label1.Text = dt.Rows.Count + "Records created, total time consume is " + ts;
}
else
{
Label1.Text = "Tidak ada data yang dipilih";
}
}
}
private DataTable ImportData(string Filepath, string Extension)
{
string connString = "";
DataTable dt = new DataTable();
switch (Extension)
{
case ".xls":
connString = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
break;
case ".xlsx":
connString = ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString;
break;
}
connString = string.Format(connString, Filepath, 1);
try
{
OleDbConnection excelConn = new OleDbConnection(connString);
OleDbCommand excelCmd = new OleDbCommand();
OleDbDataAdapter oda = new OleDbDataAdapter();
excelCmd.Connection = excelConn;
excelConn.Open();
DataTable dtexcelschema;
dtexcelschema = excelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string SheetName = dtexcelschema.Rows[0]["TABLE_NAME"].ToString();
excelConn.Close();
excelConn.Open();
excelCmd.CommandText = "Select * from [" + SheetName + "]";
oda.SelectCommand = excelCmd;
oda.Fill(dt);
excelConn.Close();
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
return dt;
}
}
。但它毕竟不会起作用。