Ich versuche, eine Excel-Datei mit C# zu lesen und erhalte immer wieder diesen Fehler: oledbexception cannot update. database or object is read-only
auf der Linie. Irgendwelche Ideen?
string connStr = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);
//file upload path
string path = FileUpload1.PostedFile.FileName;
//Create connection string to Excel work book
string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileUpload1.PostedFile.FileName + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd = new OleDbCommand("Select [Coupon], [First Name], [Last Name] from [Sheet1$]",excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(conn);
//Give your Destination table name
sqlBulk.DestinationTableName = "CPC_Coupons";
sqlBulk.WriteToServer(dReader);
excelConnection.Close();
Merci !