【问题标题】:unable to update excel sheet data into sql server database无法将excel工作表数据更新到sql server数据库
【发布时间】:2015-06-23 06:12:47
【问题描述】:

我们有一个 sql server 2008 R2 支持的 asp.net 应用程序。 可以选择从 Excel 工作表更新或插入数据库中的条目。选择要上传的文件后,当我单击更新按钮时,页面会刷新,没有其他任何反应。数据库不会更新。 我尝试调试代码,令我惊讶的是,它运行良好!尝试了很多次,同样的事情发生了。不会从应用程序更新,但会在调试时更新!我知道发布代码将帮助人们更好地理解问题,但不允许根据我组织的政策发布任何代码。我很抱歉。 非常感谢任何帮助!

【问题讨论】:

    标签: asp.net sql-server-2008 web-applications excel-2007


    【解决方案1】:
     I think in code u mentioned the Sheet name wrong so that it can't be inserted.
    
    may this code helps u..
    
    string excelConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0", path);
                    OleDbConnection connection = new OleDbConnection();
                    connection.ConnectionString = excelConnectionString;
                    string qry = "write query here "' from [Sheet1$]";
                    OleDbCommand command = new OleDbCommand(qry, connection);
                    if (connection.State == ConnectionState.Closed)
                    {
                        connection.Open();
                    }
                    DbDataReader dr = command.ExecuteReader();
                string sqlConnectionString = @"Data Source=A115-PC;Initial Catalog=ErpDB;User ID=sa;Password=XYZ@123";
                // Bulk Copy to SQL Server 
                SqlBulkCopy bulkInsert = new SqlBulkCopy(sqlConnectionString);
                bulkInsert.DestinationTableName = "MTPractiBilling"; // table name
                bulkInsert.WriteToServer(dr);
    
                DataSet dsClient = new DataSet();
                dsClient = ccSql.pBindDataSet("Select Path,FileSize,DocumentName from MTPractiBilling where UploadName='" + uploadnm + "'");
                if (dsClient.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i <= dsClient.Tables[0].Rows.Count; i++)
                    {
                        clpath = dsClient.Tables[0].Rows[i][0].ToString();
    
                        FSize = dsClient.Tables[0].Rows[i][1].ToString();
                        DocNm = dsClient.Tables[0].Rows[i][2].ToString();
                        string s = clpath;
                        string[] words = s.Split('\\');
                        clpath = words[4];
                        scpath = words[4];
                        clpath = ccSql.pReturnSingleValue “ personal query'");
                        scpath = ccSql.pReturnSingleValue("personal query' "");
                        int cnt = ccSql.pReturnIntegerValue("personal query'"'");
                        //int match = ccSql.pReturnInteger("personal query'");
                        if (cnt <= 0)
                        {
                            ccSql.pExecuteQuery("personal query''");
    
                        }
                        else
                        {
                            ccSql.pExecuteQuery("personal query''");
                            Label1.Text = DocNm.ToString() + "-" + FSize.ToString() + " Already Billed or Process..";
                            return;
                        }
                    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-23
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-25
      相关资源
      最近更新 更多