List<KeyValuePair<string, string>> allItems = new List<KeyValuePair<string, string>>();
foreach (KeyValuePair<string, KeyValuePair<string, string>> item in uniqueDependencies)
{
allItems.Add(new KeyValuePair<string, string>(item.Value.Key, item.Value.Value));
}
allItems.Sort(new KVPComparer());
foreach (KeyValuePair<string, string> item in allItems)
{
index++;
sheet.Cells[index, 1].Value = item.Key;
sheet.Cells[index, 2].Value = item.Value;
}
}
else
{
index++;
sheet.Cells[index, 1].Value = "(N/A)";
}
index += 3;
Console.WriteLine(string.Format("({0}/{1}) {2} done", i + 1, objects.Rows.Count, objectName));
}
}
connection.Close();
}
string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"/" + db + ".xls";
xls.SaveXls(path);
Console.WriteLine();
Console.WriteLine("all done!");
Console.Read();
}
}
internal class KVPComparer : IComparer<KeyValuePair<string, string>>
{
public int Compare(KeyValuePair<string, string> x, KeyValuePair<string, string> y)
{
int compare = string.Compare(x.Value, y.Value);
if (compare == 0)
return string.Compare(x.Key, y.Key);
else
return compare;
}
}
}
使用
使用很简单,编译(你得找个EXCEL输出代码。。。),在命令行(改成Win应用也可以啊)输入3个参数:数据库名、服务器名和密码。当然,大家都有自己的品味,喜欢怎么改输出格式就怎么改吧。
结论
印度资深系统分析员只是让我给个EXCEL文件,没有让我写代码,所以把我自己的研究成果发上来也无伤大雅。一般我都喜欢把写的东西弄成可重用的,不仅仅为了一个固定的目的,所以也便有了3个参数。
最后输出的的EXCEL文件有6000多行,我真怀疑到底有多少人愿意看这个文件。。。
题外话
其实漂洋过海来了澳洲,来到这个都是印度开发人员的公司,经常让我做些工作,最后都不采纳的,或许,印度人跟哪个国家的人都一样,对the new guy表现好的就要让他halt一下。。。
譬如让我用了一个星期研究SSIS,成果都出来了,最后给无视了。所以,也便有了 数据处理利器-SSIS入门与进阶 这篇文章,省得让我的研究给扔到大海。
另外一个题外话:同事给报表执行一个复杂的SQL查询(存储过程),以前都是在几秒内完成的,某天开始,要4分钟,怎么改都是要4分钟,任何机器都是,但在数据库本身所在的SSMS跑却正常。后来在业务执行插入SET ARITHABORT ON,问题解决。最后发现是SQL Plan出了问题,只需要修改一下存储过程(随便加个空行),保存便可,不需要SET ARITHABORT ON。
编辑特别推荐:
2010年上半年全国计算机等级考试试题答案
考试大教育全国计算机等级考试在线测试平台
使用BulkCopy将大量数据复制到数据库