为什么会这样? [英] why this is happening?

查看:60
本文介绍了为什么会这样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

excel文件存储在服务器上,但是数据库因此网格应该更新但是为什么它没有得到更新?请告诉我解决方案谢谢......!

The excel file is getting stored on server but the database and hence the grid is supposed to get updated but here why it is not getting updated? Please tell me the solution thanks...!

private String uploadAttachmentOnServer(FileUpload fileUpload)
    {
        String fileName = null;
        int filesize = 0;

        try
        {
            fileName = fileUpload.FileName;
            filesize = fileUpload.FileBytes.Length;
            String fileType;
            String fileSize;
            String destinationPath = Server.MapPath("./Files/"); // ExcelFiles is folder name


            String extension = Uploader.fileUpload(fileUpload, destinationPath, out fileType, out fileSize);
            String fileVirtualPath = null;
            if (extension != null)
            {
                fileVirtualPath = "../Files/" + fileUpload.FileName;
                return destinationPath + extension;
            }
            return null;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return null;
    }







protected void Upload(object sender, System.EventArgs e)
    {
        //Upload and save the file

       // string excelPath = Server.MapPath(string.Concat("/brainlines.in/starsforum.org/Forum/Files/", FileUpload1.PostedFile.FileName));

        String excelPath = uploadAttachmentOnServer(FileUpload1); //Please used this line for path & calling fuction uploadAttachmentOnServer

        //string DuplicateEtry = "These Records are Already Present..!";
        FileUpload1.SaveAs(excelPath);

        string conString = string.Empty;
        string extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
        //select virsion of Excel 2007 0r 2010
        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);

        //try
       // {
            using (OleDbConnection excel_con = new OleDbConnection(conString))
            {
                excel_con.Open();
                string sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString();
                DataTable dtExcelData = new DataTable();

                //[OPTIONAL]: It is recommended as otherwise the data will be considered as String by default.
                dtExcelData.Columns.AddRange(new DataColumn[19] { new DataColumn("NGOName", typeof(string)),
                new DataColumn("RegiID", typeof(int)),
                 new DataColumn("ExName", typeof(string)),
                  new DataColumn("Designation", typeof(string)),
                  new DataColumn("Skill", typeof(string)),
                   new DataColumn("Membership", typeof(string)),
                   new DataColumn("Address ", typeof(string)),
                 new DataColumn("City ", typeof(string)),
                 new DataColumn("Pin ", typeof(int)),
                 new DataColumn("District ", typeof(string)),
                 new DataColumn("State ", typeof(string)),
                 new DataColumn("Country ", typeof(string)),
                 new DataColumn("Landline ", typeof(int)),
                 new DataColumn("Con1", typeof(string)),
                 new DataColumn("Con2 ", typeof(string)),
                 new DataColumn("Email1 ", typeof(string)),
                 new DataColumn("Email2 ", typeof(string)),
                  new DataColumn("Website ", typeof(string)),
                   new DataColumn("Description", typeof(string)),
        });
                using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + sheet1 + "]", excel_con))
                {
                    oda.Fill(dtExcelData);
                }
                excel_con.Close();

                string consString = ConfigurationManager.ConnectionStrings["CS2"].ConnectionString;
                using (SqlConnection con = new SqlConnection(consString))
                {
                    using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
                    {
                        //Set the database table name
                        sqlBulkCopy.DestinationTableName = "dbo.ORG_Tb";

                        //[OPTIONAL]: Map the Excel columns with that of the database table
                        sqlBulkCopy.ColumnMappings.Add("NGOName", "NGOName");
                        sqlBulkCopy.ColumnMappings.Add("RegiID", "RegiID");
                        sqlBulkCopy.ColumnMappings.Add("ExName", "ExName");
                        sqlBulkCopy.ColumnMappings.Add("Designation", "Designation");
                        sqlBulkCopy.ColumnMappings.Add("Skill", "Skill");
                        sqlBulkCopy.ColumnMappings.Add("Membership", "Membership");
                        sqlBulkCopy.ColumnMappings.Add("Address", "Address");
                        sqlBulkCopy.ColumnMappings.Add("City", "City");
                        sqlBulkCopy.ColumnMappings.Add("Pin", "Pin");
                        sqlBulkCopy.ColumnMappings.Add("District", "District");
                        sqlBulkCopy.ColumnMappings.Add("State", "State");
                        sqlBulkCopy.ColumnMappings.Add("Country", "Country");
                        sqlBulkCopy.ColumnMappings.Add("Landline", "Landline");
                        sqlBulkCopy.ColumnMappings.Add("Con1", "Con1");
                        sqlBulkCopy.ColumnMappings.Add("Con2", "Con2");
                        sqlBulkCopy.ColumnMappings.Add("Email1", "Email1");
                        sqlBulkCopy.ColumnMappings.Add("Email2", "Email2");
                        sqlBulkCopy.ColumnMappings.Add("Website", "Website");
                        sqlBulkCopy.ColumnMappings.Add("Description", "Description");

                        con.Open();
                        sqlBulkCopy.WriteToServer(dtExcelData);
                        con.Close();

                        ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Message", "alert('Record Added Sucessfully')", true);
                    }
                }

            }
}

推荐答案

错误可以由各种事物引起。我建议你谷歌,请求'System.Data.OleDb.OleDbPermission类型的权限失败并使用链接来解决问题。
The error can be caused by various things. I suggest you google, "Request for the permission of type 'System.Data.OleDb.OleDbPermission failed" and use the links to troubleshoot the issue.


这篇关于为什么会这样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆