Link to home
Start Free TrialLog in
Avatar of ee_lcpaa
ee_lcpaa

asked on

No row return after calling the fillschema method

The DB server used is MySQL 5.7.16.

I have a program using MySQL .Net connector. I notice that i can read data into a dataset in using the dataadapter's Fill method.

 
However, if I call the fillschema method first and then call the full method later. Nothing is returned in the dataset (I.e. Row count is zero) with the same SELECT query used.

Pls advise the possible causes. Thanks.
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

If you have data using Fill method then you use below to get the number of rows.

DataSet.Tables[0].Rows.Count;


FillSchema method retrieves the DB schema using the SelectCommand. It creates a DataTable with all the columns to the DataColumnCollection and configures the necessary DataColumn properties. This method doesn't fill the datatable with rows, it only applies the schema.

So it is basically we get empty table with only column names and constraints.

We need to use the Fillmethod to fill the rows. There is no FULL Method available.

Hope it helps !
Avatar of ee_lcpaa
ee_lcpaa

ASKER

Sorry, there is a typo in my previous message. I am using the Fill method, not Full method.
Try this from MSDN- FillSchema After Fill Method.

public static DataSet GetCustomerData(string dataSetName,
    string connectionString)
{
    DataSet dataSet = new DataSet(dataSetName);

    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        SqlDataAdapter adapter = new SqlDataAdapter(
            "SELECT CustomerID, CompanyName, ContactName FROM dbo.Customers", connection);

        DataTableMapping mapping = adapter.TableMappings.Add("Table", "Customers");
        mapping.ColumnMappings.Add("CompanyName", "Name");
        mapping.ColumnMappings.Add("ContactName", "Contact");

        connection.Open();

        adapter.FillSchema(dataSet, SchemaType.Mapped);
        adapter.Fill(dataSet);

        return dataSet;
    }
}

Open in new window


Ref-https://msdn.microsoft.com/en-us/library/ms135707.aspx
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial