为什么通过 Unique Id 获取行时 TableName 在 SQL 中是 "Table"?
Why the TableName is "Table" in SQL while getting the row by Unique Id?
我有一个方法可以通过地址簿应用程序的 Id 获取数据集。
public DataSet GetElementById(int id)
{
string commtext = string.Format("select * from ADDRESSES where Id={0}", id);
DataSet set = new DataSet();
adapter = new OleDbDataAdapter(commtext, connection);
adapter.Fill(set);
return set;
}
我在 Access 中只有一个 table 名为 ADDRESSES
但 set.Tables[0].TableName
returns 为 Table
尽管我没有 table 这样.为什么会这样?
OleDbDataAdapter
不会尝试解析您的查询以提取 table 名称或尝试从数据库中读取名称。
无缘无故地影响性能。它默认将检索到的每个 table 命名为从 "Table" 开始的顺序 namig,然后是 "Table1" 等等。你可以看到这个 explained on MSDN
... Additional result sets are named by
appending integral values to the specified table name (for example,
"Table", "Table1", "Table2", and so on).
此外,如果您确实需要为第一个 table 分配一个值,您可以使用带有额外字符串参数的重载简单地传递 table 的名称
adapter.Fill(set, "ADDRESSES");
我有一个方法可以通过地址簿应用程序的 Id 获取数据集。
public DataSet GetElementById(int id)
{
string commtext = string.Format("select * from ADDRESSES where Id={0}", id);
DataSet set = new DataSet();
adapter = new OleDbDataAdapter(commtext, connection);
adapter.Fill(set);
return set;
}
我在 Access 中只有一个 table 名为 ADDRESSES
但 set.Tables[0].TableName
returns 为 Table
尽管我没有 table 这样.为什么会这样?
OleDbDataAdapter
不会尝试解析您的查询以提取 table 名称或尝试从数据库中读取名称。
无缘无故地影响性能。它默认将检索到的每个 table 命名为从 "Table" 开始的顺序 namig,然后是 "Table1" 等等。你可以看到这个 explained on MSDN
... Additional result sets are named by appending integral values to the specified table name (for example, "Table", "Table1", "Table2", and so on).
此外,如果您确实需要为第一个 table 分配一个值,您可以使用带有额外字符串参数的重载简单地传递 table 的名称
adapter.Fill(set, "ADDRESSES");