![](/img/trans.png)
[英]error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?)
[英]Error: The type or namespace name 'SqlCe' could not be found (are you missing a using directive or an assembly reference?)
我正在尝试将数据从 dataGridView 导出到 excel 文件。 它就像魅力一样,但我也只想拥有列的名称。 我写了下面的代码,但我无法通过这个错误得到它。 谢谢 !
错误:找不到类型或命名空间名称“SqlCe”(您是否缺少 using 指令或程序集引用?)
代码:
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;
SQL Server CE 参考: using System.Data.SqlServerCe;
没有类型,称为SqlCe
据我可以看到... ...为DataColumn
类型,你应该只使用System.Windows.Forms.DataGridViewColumn
,通过理想的using
指令对System.Windows.Forms
。 请注意, DataGridViewColumn
没有ColumnName
属性,但它有一个Name
属性:
using System.Windows.Forms;
...
foreach (DataGridViewColumn dc in dataGridView1.Columns)
{
colNames[col++] = dc.Name;
}
没有必要在那里引用SqlCe
,因为DataGridView
不是特定于提供程序的。
另请注意,如果colNames
仅包含这些列名称,则可以使用:
var colNames = dataGridView1.Columns
.Cast<DataGridViewColumn>()
.Select(c => c.Name)
.ToArray(); // Or ToList
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.