讀取一個Excel表(到transferTable),我想這些數據添加到使用SqlBulkCopy的新表(destinationTable會)之後,但我得到的錯誤:SqlBulkCopy的無法訪問表
Cannot access destination table 'test'
我已經嘗試使用默認的表名和使用方括號,但是沒有奏效。
有什麼建議嗎?
private void writeToDBButton_Click(object sender, EventArgs e) {
MakeTable();
destinationTable.TableName = "test";
testDBDataSet.Tables.Add("test");
// Connects to the sql-server using Connection.cs
SqlConnection connection = Connection.GetConnection();
using (connection) {
connection.Open();
// Uses SqlBulkCopy to copy the data from our transferTable to the destinationTable
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection)) {
bulkCopy.DestinationTableName = destinationTable.TableName;
try {
// Write from the source to the destination.
bulkCopy.WriteToServer(transferTable);
this.dataGridView2.DataSource = destinationTable;
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
connection.Close();
}
}
}
private void saveDBButton_Click(object sender, EventArgs e) {
this.Validate();
this.usersBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.testDBDataSet);
}
private void MakeTable() {
for (int counter = 0; counter < columns; counter++) {
DataColumn dummy = new DataColumn();
dummy.DataType = System.Type.GetType("System.Double");
destinationTable.Columns.Add(dummy);
}
}
你應該增加更多的相關變量,比如'C#'和數據庫,如:'SQL-server','MS-access' - '平方米l'是一個通用標籤,'access'幾乎沒有意義。 – Fionnuala 2012-01-17 12:37:13