SqlHelper bug? 还是DataAdapter bug?

igelf 2009-04-01 10:45:20

DataSet dsAllArea=new DataSet();
string sql = "SELECT * FROM tblProvince;SELECT * FROM tblCity;SELECT * FROM tblDistrict";

SqlHelper.FillDataset(SqlHelper.ConnectionString, CommandType.Text, sql, dsAllArea, new string[] { "dtblProvince", "dtblCity", "dtblDistrict" });

这时dsAllArea.Tables[2].TableName ="Table2"
最后一个不起作用.
自己又加了下面这句.
dsAllArea.Tables[2].TableName = "dtblDistrict";
...全文
133 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
igelf 2009-04-02
  • 打赏
  • 举报
回复
解决了.
kkun_3yue3 2009-04-02
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 igelf 的回复:]
引用 11 楼 kkun_3yue3 的回复:

试下10楼的代码,
PS:你用的是山寨版的SQLHELPER
原版的上PETSHOP里找

我之前都是用自己的类.换公司了,就用公司的这个了.不知道是不是山寨的.
[/Quote]

能解决你的问题就成,山寨不山寨的吧无所谓
igelf 2009-04-02
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 kkun_3yue3 的回复:]
试下10楼的代码,
PS:你用的是山寨版的SQLHELPER
原版的上PETSHOP里找
[/Quote]
我之前都是用自己的类.换公司了,就用公司的这个了.不知道是不是山寨的.
kkun_3yue3 2009-04-02
  • 打赏
  • 举报
回复

string tableName = "Table";
for (int index = 0; index < tableNames.Length; index++)
{
if (tableNames[index] == null || tableNames[index].Length == 0) throw new ArgumentException("The tableNames parameter must contain a list of tables, a value was provided as null or empty string.", "tableNames");
dataAdapter.TableMappings.Add(tableName, tableNames[index]);
tableName += (index + 1).ToString();//注意这一行
}



循环后的tableName为
Table
Table1
Table12
Table123
Table1234
Table12345
..........

kkun_3yue3 2009-04-02
  • 打赏
  • 举报
回复
试下10楼的代码,
PS:你用的是山寨版的SQLHELPER
原版的上PETSHOP里找
kkun_3yue3 2009-04-02
  • 打赏
  • 举报
回复

using( SqlDataAdapter dataAdapter = new SqlDataAdapter( cmd ) )
{

// Add the table mappings specified by the user
if( tableNames != null && tableNames.Length > 0 )
{
string tableName = "Table";
dataAdapter.TableMappings.Add( tableName, tableNames[ 0 ] );
for( int index = 1; index < tableNames.Length; index++ )
{
if( tableNames[index] == null || tableNames[index].Length == 0 ) throw new ArgumentException( "The tableNames parameter must contain a list of tables, a value was provided as null or empty string.", "tableNames" );
dataAdapter.TableMappings.Add( tableName + index, tableNames[ index ] );
//tableName += ( index + 1 ).ToString();
}
}

// Fill the DataSet using default values for DataTable names, etc
dataAdapter.Fill( dataSet );
}
kkun_3yue3 2009-04-02
  • 打赏
  • 举报
回复
曾经改过这样的代码,但我也不清楚这个版本的"SQLHELPER"是从哪里流传出来哒!

igelf 2009-04-02
  • 打赏
  • 举报
回复

// 执行命令
using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
{

// 追加表映射
if (tableNames != null && tableNames.Length > 0)
{
string tableName = "Table";
for (int index = 0; index < tableNames.Length; index++)
{
if (tableNames[index] == null || tableNames[index].Length == 0) throw new ArgumentException("The tableNames parameter must contain a list of tables, a value was provided as null or empty string.", "tableNames");
dataAdapter.TableMappings.Add(tableName, tableNames[index]);
tableName += (index + 1).ToString();
}
}

// 填充数据集使用默认表名称
dataAdapter.Fill(dataSet);

// 清除参数,以便再次使用.
command.Parameters.Clear();
}

SqlHelper.cs的代码.
wuyq11 2009-04-01
  • 打赏
  • 举报
回复
dataAdapter.TableMappings.Add("Table1","aa");
http://www.cnblogs.com/torome/articles/322332.html
wellcc 2009-04-01
  • 打赏
  • 举报
回复
自己改一下用吧
igelf 2009-04-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 kyoybs 的回复:]
SqlHelper.FillDataset 是自己写的方法? 好像不是.net里的吧
[/Quote]
是SqlHelper类的方法.


SqlHelper.FillDataset(SqlHelper.ConnectionString, CommandType.Text, sql, dsAllArea, new string[] { "dtblProvince", "dtblCity", "dtblDistrict" });

执行好之后.
dsAllArea.Tables[0].TableName ="dtblProvince"
dsAllArea.Tables[1].TableName ="dtblCity"
dsAllArea.Tables[2].TableName ="Table2"


最后一个不起作用.
阿非 2009-04-01
  • 打赏
  • 举报
回复
?
kyoybs 2009-04-01
  • 打赏
  • 举报
回复
SqlHelper.FillDataset 是自己写的方法? 好像不是.net里的吧
阿非 2009-04-01
  • 打赏
  • 举报
回复
那个方法 内部 是怎么操作的,你最好断点调试一下

你也可以把 代码在这贴一下,我帮你看看
qq2013 2009-04-01
  • 打赏
  • 举报
回复
ding

62,052

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧