i have read the other question with the same one without the OldeDb namespace in it. But I am still having a problem
I am creating a UWP app, and I want to upload a data from an Excel file to a DataGridView.
So this is my code
This is my reference code
using System.Collections.Generic;
using Windows.UI.Xaml.Controls;
using System.Data;
using Microsoft.Toolkit.Uwp.UI.Controls;
using System;
using System.IO;
using System.Data.OleDb
then this is my code on uploading my excel file
String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fullDirectory + ";Extended Properties='Excel 12.0 XML;HDR=YES;';";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand oconn = new OleDbCommand("Select * From [" + "2018" + "$]", con);
And this is my error code
Error CS0246 The type or namespace name 'OleDbCommand' could not be found (are you missing a using directive or an assembly reference?)
Any ideas why this is occurring? Thanks
Full Code
using System.Collections.Generic;
using Windows.UI.Xaml.Controls;
using System.Data;
using Microsoft.Toolkit.Uwp.UI.Controls;
using System;
using System.IO;
using System.Data.OleDb;
namespace App
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void SaveButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
}
private void CancelButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
}
private void AppBarButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
if (this.Frame.CanGoBack)
{
this.Frame.GoBack();
}
}
private async void BtnOpenAttendanceFileDialog_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
picker.FileTypeFilter.Clear();
picker.FileTypeFilter.Add(".xls");
picker.FileTypeFilter.Add(".xlsx");
picker.FileTypeFilter.Add(".dat");
picker.FileTypeFilter.Add(".csv");
Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
this.txtFileLocation.Text = file.Path;
}
else
{
}
}
private void BtnLoadFile_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
string fileDirectory = Path.GetDirectoryName(txtFileLocation.Text.Trim());
string fileName = Path.GetDirectoryName(txtFileLocation.Text.Trim());
string fullDirectory = txtFileLocation.Text.Trim();
String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fullDirectory + ";Extended Properties='Excel 12.0 XML;HDR=YES;';";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand oconn = new OleDbCommand("Select * From [" + "2018" + "$]", con);
}
}
}
;afterusing System.Data.OleDbin your own code?1.have you added oledb as a reference to your project in your solution?2.Try pressingctrl + .when you are standing onnew OleDbConnection(constr);Does it say anything?3.Try removing the using clause and do step2again.