c# - sql server 中百分比列的数据类型是什么?

标签 c# asp.net sql sql-server

我正在使用 ASP.NET,我想将 Excel 工作表导入到 SQL Server 中的表中。 问题是我的 Excel 的一列有百分比类型(例如:25%)。您是否有解决方案将该百分比值存储在我的 SQL Server 表中?

如果您愿意,我会发布我的代码:

 protected void Button1_Click(object sender, EventArgs e)
        {

            if (FileUpload1.HasFile)
            {
                string path = string.Concat((Server.MapPath("~/temp/" + FileUpload1.FileName)));
                FileUpload1.PostedFile.SaveAs(path);
                OleDbConnection OleDbcon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;");

                // Feuil1 est la première page du fichier Excel
                OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Feuil1$]", OleDbcon);
                OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(cmd);

                OleDbcon.Open();
                DbDataReader dr = cmd.ExecuteReader();
                // configuration de la chaîne de connexion de SQL Server
                string con_str = @"Data Source=.;Initial Catalog=projetDGCS;Integrated Security=True";

                // On copie dans SQL Server 
                SqlBulkCopy bulkInsert = new SqlBulkCopy(con_str);
                // On mets le nom de la table de destination
                bulkInsert.DestinationTableName = "reponse";
                bulkInsert.WriteToServer(dr);
                OleDbcon.Close();
                // On a stocké le fichier Excel dans le dossier "temp" et on le supprime après 
                Array.ForEach(Directory.GetFiles((Server.MapPath("~/temp/"))), File.Delete);
                Label1.ForeColor = Color.Green;
                Label1.Text = "Insertion réussie !";

            }

最佳答案

Excel 没有字段的百分比类型。它具有数字字段的百分比格式 - 与您的应用程序可以应用的相同。 0.01 = 1%(至少我的学校是这么教的)。

这是非常客观的 - 您可以在任何数字字段中存储百分比值。如何格式化它以及是否使用例如tinyint(1 = 1%)完全取决于您作为程序员。

关于c# - sql server 中百分比列的数据类型是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24221253/

相关文章:

c# - 如何以正确的方式加入 firebase 查询的结果

c# - WPF 绑定(bind) View 模型

sql - 如何在 Postgresql 中将字段转换为 JSON

asp.net - 我的解决方案中有两个 Web 项目,要部署哪一个

mysql - 如何从一列的结果列表中选择第二列作为引用?

php - 使用 ODBC Firebird 驱动程序在 PHP 中不带 FROM 子句的 SQL SELECT

c# - 未在自定义凭据上设置 WCF 证书

c# - 在 docuSign 中的用户之间传输信封

c# - 通过 SSL 发送请求时无法发布文件数据

asp.net - mvc 大写模型与小写模型