Dopo aver letto in un excel fogli (a transferTable), voglio aggiungere che i dati in una nuova tabella (destinationTable) utilizzando SqlBulkCopy, ma sto ottenendo l'errore:SqlBulkCopy non può accedere alla tabella
Cannot access destination table 'test'
Ho provato a utilizzare il nome di tabulazione predefinito e l'utilizzo di parentesi quadre, ma non ha funzionato.
Qualche suggerimento?
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);
}
}
Si dovrebbe aggiungere tag più rilevanti, come ad esempio 'C#' e un database, ad esempio 'sql-server',' MS-access' - 'mq l' è un tag generico e 'access' è quasi privo di significato. – Fionnuala