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:


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.


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"

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.

3 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Support us!

If you like this site please help and make click on any of these buttons!