We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DataGrid Validatin with ADO

Hello,

I'm having trouble implementing the IDataErrorInfo
while using an OledConnection.
How do I set up the property to return the column's value?

Here is my code:



public partial class MainWindow : Window
{
ObservableCollection collec = new ObservableCollection();
public MainWindow()
{
InitializeComponent();

string file = @"..\..\sample.xls";
OleDbConnection oConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + file +";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;\"");
oConn.Open();
OleDbCommand oCmd = new OleDbCommand("SELECT * FROM [Sheet1$]",oConn);
OleDbDataReader oReader = oCmd.ExecuteReader();

while (oReader.Read())
{
object[] rowValues = new object[oReader.FieldCount];
oReader.GetValues(rowValues);
collec.Add(new Order {OrderID= Int32.Parse(rowValues[0].ToString()),CustomerID=rowValues[1].ToString(),EmployeeID=rowValues[2].ToString(),ShipName=rowValues[3].ToString(),ShipAddress=rowValues[4].ToString(),ShipCity=rowValues[5].ToString(),Freight=rowValues[6].ToString() });
}

dataGrid.ItemsSource = collec;
}
}

public class Order : System.ComponentModel.IDataErrorInfo
{
public int OrderID { get; set; }
public string CustomerID { get; set; }
public string EmployeeID { get; set; }
public string ShipName { get; set; }
public string ShipAddress { get; set; }
public string ShipCity { get; set; }
public string Freight { get; set; }

public string Error
{
get { return string.Empty; }
}

public string this[string columnName]
{
get
{
var result = string.Empty;
if (columnName == "OrderID")
{
//this doesn't work:
if(this.OrderID.Value =...

}
return result;
}
}


}


thanks...



1 Reply

RA Rajasekar Syncfusion Team March 23, 2011 01:51 PM UTC

Hi Assaf,

Thanks for choosing Syncfusion products.

The query posted in this forum is similar to this incident #78560. Regarding this query we have posted solution in the incident #78560. Please follow this incident for further clarification.

For Your Reference, please find the sample in the below location,

Sample:< http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=GDC_Excel_OleDbConnection369360711.zip >

Please let us know if you have any queries.

Thanks,
Rajasekar




Loader.
Live Chat Icon For mobile
Up arrow icon