Iam получает ошибку, так как 'oledbcommand' не содержит определения для 'executenonqueryasync' и никакого метода расширения
Iam получает ошибку, так как 'OleDbCommand' не содержит определения для 'ExecuteNonQueryAsync' и не может быть найден метод расширения 'ExecuteNonQueryAsync', принимающий первый аргумент типа 'OleDbCommand' (вы пропускаете директиву using или ссылку на сборку?)
Он подходит как для ExecuteNonQueryAsyncpre>, Так и для OpenAsyn
Что я уже пробовал:
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data.OleDb; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ExcelElement { public class Staff { public int CustomerID { get; set; } public string Name { get; set; } public string Email { get; set; } public string Size { get; set; } public string Address { get; set; } } class ExcelDataService { OleDbConnection Conn; OleDbCommand Cmd; public ExcelDataService() { string ExcelFilePath = @"C:\Users\Pulztec-3\Desktop\\book1.xlsx"; string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ExcelFilePath + ";Extended Properties=Excel 12.0;Persist Security Info=True"; Conn = new OleDbConnection(excelConnectionString); } /// <summary> /// Method to Get All the Records from Excel /// </summary> /// <returns></returns> /// public async Task<ObservableCollection<Staff>> ReadRecordFromEXCELAsync() { ObservableCollection<Staff> Staffs = new ObservableCollection<Staff>(); await Conn.OpenAsync(); Cmd = new OleDbCommand(); Cmd.Connection = Conn; Cmd.CommandText = "Select * from [Sheet1$]"; var Reader = await Cmd.ExecuteReaderAsync(); while (Reader.Read()) { Staffs.Add(new Staff() { CustomerID = Convert.ToInt32(Reader["CustomerID"]), Name = Reader["Name"].ToString(), Email = Reader["Email"].ToString(), Size = Reader["Size"].ToString(), Address = Reader["Address"].ToString() }); } Reader.Close(); Conn.Close(); return Staffs; } /// <summary> /// Method to Insert Record in the Excel /// S1. If the EmpNo =0, then the Operation is Skipped. /// S2. If the Student is already exist, then it is taken for Update /// </summary> /// <param name="Emp"></param> public async Task<bool> ManageExcelRecordsAsync(Staff staff) { bool IsSave = false; if (staff.CustomerID != 0) { await Conn.OpenAsync(); Cmd = new OleDbCommand(); Cmd.Connection = Conn; Cmd.Parameters.AddWithValue("@CustomerID", staff.CustomerID); Cmd.Parameters.AddWithValue("@Name", staff.Name); Cmd.Parameters.AddWithValue("@Email", staff.Email); Cmd.Parameters.AddWithValue("@Size", staff.Size); Cmd.Parameters.AddWithValue("@Address", staff.Address); if (!IsStudentRecordExistAsync(staff).Result) { Cmd.CommandText = "Insert into [Sheet1$] values (@CustomerID,@Name,@Email,@Size,@Address)"; } else { Cmd.CommandText = "Update [Sheet1$] set CustomerID=@CustomerID,Name=@Name,Email=@Email,Size=@Size,Address=@Address where CustomerID=@CustomerID"; } int result = await Cmd.ExecuteNonQueryAsync(); if (result > 0) { IsSave = true; } Conn.Close(); } return IsSave; } /// <summary> /// The method to check if the record is already available /// in the workgroup /// </summary> /// <param name="emp"></param> /// <returns></returns> private async Task<bool> IsStudentRecordExistAsync(Staff staff) { bool IsRecordExist = false; Cmd.CommandText = "Select * from [Sheet1$] where CustomerID=@CustomerID"; var Reader = await Cmd.ExecuteReaderAsync(); if (Reader.HasRows) { IsRecordExist = true; } Reader.Close(); return IsRecordExist; } } }