c#控制台应用程序,excel数据到字典用于sql查询
我有一个程序,目前在控制台中打印excel工作表,但我希望能够存储该信息,然后将其放入SQL表中 我将如何使用get和set来实现这一点 我有两门课 Program.csc#控制台应用程序,excel数据到字典用于sql查询,c#,sql,excel,import,C#,Sql,Excel,Import,我有一个程序,目前在控制台中打印excel工作表,但我希望能够存储该信息,然后将其放入SQL表中 我将如何使用get和set来实现这一点 我有两门课 Program.cs class Program { private static void Main(string[] args) { Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.
class Program {
private static void Main(string[] args) {
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\Users\praktikant\source\Console\KPIimport\KPIimport\KPI_Bestyrelsen.xlsx");
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
object[,] valueArray = (object[,])xlRange.get_Value(Excel.XlRangeValueDataType.xlRangeValueDefault);
String[,] arr = new String[rowCount, colCount];
for (int i = 1; i <= rowCount; i++) {
for (int j = 1; j <= colCount; j++) {
if (j == 1)
Console.Write("\r\n");
if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null) {
//Console.Write(xlRange.Cells[i, j].Value2.ToString() + "\t");
arr[i, j] = valueArray[i, j].ToString();
Console.WriteLine(arr[i, j]);
}
}
}
//cleanup
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.ReleaseComObject(xlRange);
Marshal.ReleaseComObject(xlWorksheet);
//close and release
xlWorkbook.Close();
Marshal.ReleaseComObject(xlWorkbook);
//quit and release
xlApp.Quit();
Marshal.ReleaseComObject(xlApp);
}
}
为什么要创建Items.cs?与数据库连接和通信的代码在哪里?@Markus数据库连接现在并不重要,重要的是我将excel数据存储在某个地方,以便以后插入,我编写sql只是为了给我想用它做的事情提供一些上下文您已经将其存储在“字典”中了是的,但它没有按键排序,所以我不知道如何使用它进行查询
class Items {
public DateTime Dato { get; set; }
public string Portal { get; set; }
public decimal Home_oms { get; set; }
}