简体   繁体   English

错误:找不到类型或命名空间名称“SqlCe”(您是否缺少 using 指令或程序集引用?)

[英]Error: The type or namespace name 'SqlCe' could not be found (are you missing a using directive or an assembly reference?)

I'm trying to export my data from a dataGridView to an excel file.我正在尝试将数据从 dataGridView 导出到 excel 文件。 It works like charm, but I just want to have the name of the columns too.它就像魅力一样,但我也只想拥有列的名称。 I wrote the following code, but I can't get it with this error.我写了下面的代码,但我无法通过这个错误得到它。 Thanks !谢谢 !

Error: The type or namespace name 'SqlCe' could not be found (are you missing a using directive or an assembly reference?)错误:找不到类型或命名空间名称“SqlCe”(您是否缺少 using 指令或程序集引用?)

Code:代码:

foreach (SqlCe.Data.DataColumn dc in dataGridView1.Columns)
                colNames[col++] = dc.ColumnName;

char lastColumn = (char)(65 + dataGridView1.Columns.Count - 1);

xlWorkSheet.get_Range("A1", lastColumn + "1").Value2 = colNames;
xlWorkSheet.get_Range("A1", lastColumn + "1").Font.Bold = true;
xlWorkSheet.get_Range("A1", lastColumn + "1").VerticalAlignment= Excel.XlVAlign.xlVAlignCenter;

The reference for SQL Server CE: using System.Data.SqlServerCe; SQL Server CE 参考: using System.Data.SqlServerCe;

There is no type called SqlCe as far as I can see... for the DataColumn type, you should just be using System.Windows.Forms.DataGridViewColumn , ideally via a using directive for System.Windows.Forms .没有类型,称为SqlCe据我可以看到... ...为DataColumn类型,你应该只使用System.Windows.Forms.DataGridViewColumn ,通过理想的using指令对System.Windows.Forms Note that DataGridViewColumn doesn't have a ColumnName property, but it does have a Name property:请注意, DataGridViewColumn没有ColumnName属性,但它有一个Name属性:

using System.Windows.Forms;
...
foreach (DataGridViewColumn  dc in dataGridView1.Columns)
{
    colNames[col++] = dc.Name;
}

There's no need to refer to SqlCe there, because a DataGridView isn't provider-specific.没有必要在那里引用SqlCe ,因为DataGridView不是特定于提供程序的。

Also note that if colNames just contains these column names, you could use:另请注意,如果colNames包含这些列名称,则可以使用:

var colNames = dataGridView1.Columns
                            .Cast<DataGridViewColumn>()
                            .Select(c => c.Name)
                            .ToArray(); // Or ToList

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误 CS0246:找不到类型或命名空间名称“IWebHostEnvironment”(您是否缺少 using 指令或程序集引用?) - error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?) 为什么会出现这个错误? “找不到类型或名称空间名称&#39;c&#39;(您是否缺少using指令或程序集引用?)” - Why this error ? “The type or namespace name 'c' could not be found (are you missing a using directive or an assembly reference?)” 错误1找不到类型或名称空间名称&#39;FPSTimer&#39;(您是否缺少using指令或程序集引用?) - Error 1 The type or namespace name 'FPSTimer' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246:找不到类型或命名空间名称“BannerPosition”是否缺少 using 指令或程序集引用? - error CS0246: The type or namespace name 'BannerPosition' could not be found are you missing a using directive or an assembly reference? c#错误1找不到类型或名称空间名称”(是否缺少using指令或程序集引用?) - c# Error 1 The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?) 获取错误找不到类型或命名空间名称“T”(您是否缺少using指令或程序集引用?) - Getting error The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?) 错误1找不到类型或名称空间名称&#39;ProductServiceClient&#39;(您是否缺少using指令或程序集引用?) - Error 1 The type or namespace name 'ProductServiceClient' could not be found (are you missing a using directive or an assembly reference?) 错误14找不到类型或命名空间名称“Document”(您是否缺少using指令或程序集引用?) - Error 14 The type or namespace name 'Document' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246 找不到类型或命名空间名称“CreateRandomAnswersForKey”(您是否缺少 using 指令或程序集引用?)? - Error CS0246 The type or namespace name 'CreateRandomAnswersForKey' could not be found (are you missing a using directive or an assembly reference?)? 错误 CS0246:找不到类型或命名空间名称“Npgsql”(您是否缺少 using 指令或程序集引用?) - error CS0246: The type or namespace name 'Npgsql' could not be found (are you missing a using directive or an assembly reference?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM