我有一個簡單的按鈕事件來將excel表單導入到數據庫中。的碼片/部分是這樣的..在數據庫中插入空的excel單元格作爲空白單元格
private void button6_Click(object sender, EventArgs e)
{
OpenFileDialog theDialog = new OpenFileDialog();
theDialog.Title = "Open Text File";
theDialog.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm;*.xltm;*.xltx";
theDialog.InitialDirectory = @"C:\";
if (theDialog.ShowDialog() == DialogResult.OK)
{
try
{
foreach (var worksheetx in Workbook.Worksheets(theDialog.FileName.ToString()))
{
foreach (var row in worksheetx.Rows)
{
String Temp = @"INSERT INTO [dbo].[myTable]
([Status]
,[NName]
,[Notes]
)
VALUES
('<Status>'
,'<NName>'
,'<Notes>'
)";
String Temp1 = Temp;
bool ForceContinue = false;
foreach (var cell in row.Cells)
{
if (cell != null)
{
if (cell.ColumnIndex == 0)Temp1 = Temp1.Replace("<Status>", cell.Text);
if (cell.ColumnIndex == 1)Temp1 = Temp1.Replace("<NName>", cell.Text);
if (cell.ColumnIndex == 2)Temp1 = Temp1.Replace("<Notes>", cell.Text);
}
else
{
//Looking for this part- How to insert 'NULL' or Blank cell.Text
}
}
DBConn.Execute(Temp1);
例如,如果我的excel表列 - '注意' 是像
| Check |
| |
| |
它當前插入DB等
| Check |
|<Notes>|
|<Notes>|
我希望它是這樣的空白插入爲空白
| Check |
| |
| |