Solution – Cannot serialize the DataTable. DataTable name is not set

September 19th, 2012 | Posted by Nitesh Luharuka in .Net

.Net Library provides a very easy way to generate the XML schema of any dataset/data table using the WriteXmlSchema(). For this, we need to execute the following code:

dt.WriteXmlSchema("sample.xsd")

Using the above code, the schema of the datatable dt will be retrieved and saved in sample.xsd file. However, sometimes using the above code throws an error at run time as “Cannot serialize the DataTable. DataTable name is not set“.

As the error implies, a data table can not be serialized until or unless it has a name. To resolve this error, we need to provide a name to the data table using the TableName property. Assign the data table a name before calling the WriteXmlSchema() and you’re done.

dt.tableName=”MySampleTable”

The complete sample to retrieve the Xml Schema of a Data table looks as below. Ensure that the TableName property is assigned after getting the data in the data table, else you will continue to get the error!

Dim dt As New DataTable()
dt = GetData() //Get the data here
dt.TableName = "MySampleTable"
dt.WriteXmlSchema("sample.xsd")

Hope this post helps you!

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

  • Ellingsen

    Good post and right to the point. I don’t know if this is in fact the best place to ask but do you folks have any idea where to get some professional writers? Thanks in advance :)

  • Beats

    That’s a nice post.

  • gurunathan natarajan

    Thank You //// It’s Work

Close
Please support the site
By clicking any of these buttons you help our site to get better