Hi
Message = "Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource."
C#
SAPbobsCOM.SBObob obj = _oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge);
SAPbobsCOM.Recordset rs = _oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
rs = obj.GetBPList(SAPbobsCOM.BoCardTypes.cCustomer);
int count = rs.RecordCount;
rs.DoQuery("SELECT CardCode,CardName FROM OCRD");
grdBP.DataSource = rs;
grdBP.DataBind();Thanks

Vijay Pratap SinghRank #381 · 6.6K reputationPosted Dec 28, 2023, 2:00 AM EST
SAPbobsCOM.SBObob obj = _oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge); SAPbobsCOM.Recordset rs = _oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); rs = obj.GetBPList(SAPbobsCOM.BoCardTypes.cCustomer); // Convert the Recordset to a DataTable DataTable dataTable = new DataTable(); dataTable.Load(rs, LoadOption.OverwriteChanges); // Now set the DataTable as the data source for the grid grdBP.DataSource = dataTable; grdBP.DataBind();To resolve this issue, you need to convert the data from the
Recordsetto a suitable data structure that implements one of the required interfaces. One common approach is to load the data into aDataTableand then set theDataTableas the data source for your grid.Hope this will help
Prasad RaveendranRank #320 · 7.8K reputationPosted Dec 28, 2023, 11:29 PM EST
Here's an example of how you might resolve this issue by converting the
Recordsetto a compatible data source before binding it togrdBP. You can use aDataTableas an intermediary data structure:// Assuming grdBP is a DataGridView or a similar UI control // Create a DataTable to hold the data from the Recordset DataTable dataTable = new DataTable(); dataTable.Columns.Add("CardCode"); dataTable.Columns.Add("CardName"); // Move the data from the Recordset to the DataTable if (!rs.EoF) { while (!rs.EoF) { DataRow row = dataTable.NewRow(); row["CardCode"] = rs.Fields.Item("CardCode").Value; row["CardName"] = rs.Fields.Item("CardName").Value; dataTable.Rows.Add(row); rs.MoveNext(); } } // Set the DataTable as the DataSource for grdBP grdBP.DataSource = dataTable; grdBP.DataBind();This code creates a
DataTable, fills it with the data from theRecordset, and then sets theDataTableas the data source forgrdBP.Remember to replace
DataGridViewwith the appropriate UI control that you're using in your application (e.g., GridView, DataGrid, etc.).This approach ensures that the data source (
DataTable) being assigned to the grid control is compatible with the data binding requirements.Jayraj ChhayaRank #304 · 8.2K reputationPosted Dec 28, 2023, 4:09 AM EST
The error message "Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource" suggests that the
CauseDataSourceproperty of thegrdBPcontrol is expecting a specific type, but the providedrsobject does not match that type.The cause of the issue is that the
SolutionDataSourceproperty of thegrdBPcontrol expects a data source that implements either theIListSource,IEnumerable, orIDataSourceinterface. However, thersobject in the code is of typeSAPbobsCOM.Recordset, which does not implement any of these interfaces.To resolve the issue, we need to convert the
Recordsetobject to a compatible data source type before assigning it to theDataSourceproperty of thegrdBPcontrol. One way to achieve this is by converting theRecordsetto aDataTableobject, which implements theIListSourceinterface.Here's an updated version of the code that includes the necessary conversion:
SAPbobsCOM.SBObob obj = _oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge); SAPbobsCOM.Recordset rs = _oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); rs = obj.GetBPList(SAPbobsCOM.BoCardTypes.cCustomer); int count = rs.RecordCount; rs.DoQuery("SELECT CardCode,CardName FROM OCRD"); // Convert Recordset to DataTable DataTable dt = new DataTable(); dt.Load(rs.GetFixedRecordset()); grdBP.DataSource = dt; grdBP.DataBind();In the updated code, we create a new
DataTableobject and load the data from theRecordsetusing theLoadmethod. This converts theRecordsetinto aDataTablethat can be assigned to theDataSourceproperty of thegrdBPcontrol.Asma KhalidRank #160 · 14.7K reputationPosted Dec 28, 2023, 1:25 PM EST
The main issue you are facing is that your data source is basically a table and you are assigning a table to a set of rows. YOu need to initiate dataable variable to mapp the table as data source.
Thanks & Regards,
Jignesh KumarRank #91 · 22.9K reputationPosted Dec 29, 2023, 6:36 AM EST
Hello Ramco,
Have you check what it return type of this ?
rs.DoQuery("SELECT CardCode,CardName FROM OCRD");You need to change here, just convert above one into list.
Ramco RamcoRank #462 · 5.4K reputationPosted Dec 29, 2023, 10:55 PM EST
Hi Jignesh
I am not getting tolist option
Thanks
Satyaprakash SamantarayRank #101 · 21.1K reputationPosted Dec 28, 2023, 3:09 AM EST
Make sure you should use the item it fills and for this u can load the data into a
DataTableand then set theDataTableas the data source for your gridview control.Refer below link,
https://www.experts-exchange.com/questions/23196023/Error-Data-source-is-an-invalid-type-It-must-be-either-an-IListSource-IEnumerable-or-IDataSource.html