C# 如何将字典变量传递给另一个过程

C# 如何将字典变量传递给另一个过程,c#,dictionary,sql-server-2005,visual-studio-2008,C#,Dictionary,Sql Server 2005,Visual Studio 2008,我正在开发一个C#VS2008/SQL Server网站应用程序。我以前从未使用过Dictionary类,但我正在尝试用Dictionary变量替换哈希表 以下是我的aspx.cs代码的一部分: ... Dictionary<string, string> openWith = new Dictionary<string, string>(); for (int col = 0; col < headers.Length; col++) { @temp =

我正在开发一个C#VS2008/SQL Server网站应用程序。我以前从未使用过Dictionary类,但我正在尝试用Dictionary变量替换哈希表

以下是我的aspx.cs代码的一部分:

...
Dictionary<string, string> openWith = new Dictionary<string, string>(); 

for (int col = 0; col < headers.Length; col++)
{
   @temp = (col + 1);
   @tempS = @temp.ToString();
   @tempT = "@col" + @temp.ToString();
   ...
   openWith.Add(@tempT, headers[col]);
}
...
for (int r = 0; r < myInputFile.Rows.Count; r++)
 { resultLabel.Text = ADONET_methods.AppendDataCT(myInputFile, openWith); }
。。。
Dictionary openWith=new Dictionary();
for(int col=0;col
但这在最后一行给了我一个编译器错误: 参数“2”:无法从“System.Collections.Generic.Dictionary”转换为“string”


如何将整个openWith变量传递给AppendDataCT?AppendDataCT是调用我的SQL存储过程的方法。我希望传入整行,其中每行都有一组唯一的值,我希望将这些值添加到数据库表中。例如,如果每行需要单元格A、B和C的值,那么我想将这3个值传递给AppendDataCT,其中所有这些值都是字符串。如何使用字典?问题不在于你的字典,也不在于你如何传递字典。问题在于您的方法
AppendDataCT
,它需要的是
字符串
参数,而不是
字典

假设这样,你可能想要这样的东西

foreach( KeyValuePair<string,string> item in openWith )
{
    resultLabel.Text = ADONET_methods.AppendDataCT(myInputFile, item.Value);
}
foreach(openWith中的KeyValuePair项)
{
resultLabel.Text=ADONET_methods.AppendDataCT(myInputFile,item.Value);
}
这将遍历您的字典,并针对每对[键,值]
使用配对中的值调用AppendDataCT方法。

从字典中提取并作为字符串传递