下面的代码很梦幻。但它可以变得更紧凑和 C#'ish 吗?特别是我对两个问题有怀疑。
fill
通过将变量用作参数来填充变量不是很丑陋(旧的 C 风格)吗?- 可以使代码更紧凑而不是通过
String
?
C#
String
connectionString = "...",
sqlStatement = "select * from Test",
output = "";
SqlDataAdapter adapter = new SqlDataAdapter(sqlStatement, connectionString);
DataSet dataSet = new DataSet("Contents");
adapter.Fill(dataSet, "Test");
StringWriter stringWriter=new StringWriter();
dataSet.WriteXml(new XmlTextWriter(stringWriter));
XmlDocument document = new XmlDocument();
output = stringWriter.ToString();
document.LoadXml(output);