WARNING: Error in the Data Access Application Block (C# only)

  • Thread starter Cowboy \(Gregory A. Beamer\)
  • Start date
C

Cowboy \(Gregory A. Beamer\)

I found an error in the Data Access application, specifically in the
tableMappings in the FillDataSet() overload with the following signature:

private static void FillDataset(SqlConnection connection, SqlTransaction
transaction,
CommandType commandType, string commandText, DataSet dataSet,
string[] tableNames, params SqlParameter[] commandParameters)
{
}

The code in question is line 1840 (C#), which reads:

tableName += (index + 1).ToString();

Assuming the following string:

string tableNames = {"MyTable1", "MyTable2", "MyTable3", "MyTable4" };

this original statement will produce:

dataAdapter.TableMappings.Add("Table" , "MyTable1");
dataAdapter.TableMappings.Add("Table1" , "MyTable2");
dataAdapter.TableMappings.Add("Table12" , "MyTable3");
dataAdapter.TableMappings.Add("Table123" , "MyTable4");

This is incorrect. It should be:

dataAdapter.TableMappings.Add("Table" , "MyTable1");
dataAdapter.TableMappings.Add("Table1" , "MyTable2");
dataAdapter.TableMappings.Add("Table2" , "MyTable3");
dataAdapter.TableMappings.Add("Table3" , "MyTable4");

FIX: The corrected version of this line (for reference: line 1840):

tableName = tableName + (index + 1).ToString();

NOTE that the VB.NET version is correct, with this string:
tableName = tableName & (index + 1).ToString()

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
C

Cowboy \(Gregory A. Beamer\)

FIX (incorrect):
tableName = tableName + (index + 1).ToString();

FIX (correct):
tableName = "Table" + (index + 1).ToString();

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
Cowboy (Gregory A. Beamer) said:
I found an error in the Data Access application, specifically in the
tableMappings in the FillDataSet() overload with the following signature:

private static void FillDataset(SqlConnection connection, SqlTransaction
transaction,
CommandType commandType, string commandText, DataSet dataSet,
string[] tableNames, params SqlParameter[] commandParameters)
{
}

The code in question is line 1840 (C#), which reads:

tableName += (index + 1).ToString();

Assuming the following string:

string tableNames = {"MyTable1", "MyTable2", "MyTable3", "MyTable4" };

this original statement will produce:

dataAdapter.TableMappings.Add("Table" , "MyTable1");
dataAdapter.TableMappings.Add("Table1" , "MyTable2");
dataAdapter.TableMappings.Add("Table12" , "MyTable3");
dataAdapter.TableMappings.Add("Table123" , "MyTable4");

This is incorrect. It should be:

dataAdapter.TableMappings.Add("Table" , "MyTable1");
dataAdapter.TableMappings.Add("Table1" , "MyTable2");
dataAdapter.TableMappings.Add("Table2" , "MyTable3");
dataAdapter.TableMappings.Add("Table3" , "MyTable4");

FIX: The corrected version of this line (for reference: line 1840):

tableName = tableName + (index + 1).ToString();

NOTE that the VB.NET version is correct, with this string:
tableName = tableName & (index + 1).ToString()

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top