读取一个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