【发布时间】:2018-04-13 02:32:54
【问题描述】:
在我的数据库表中,我有一个 XML 数据类型的列名“SectionDatatable”。在我的 C# 代码中,在我将数据库连接到我的数据库并进行查询以获取我的数据库中的 XML 格式 UserDefinedSectionData 之后。我需要将 XML Datatype 中的“SectionDatatable”转换为 DataSet,我该怎么做。我卡了1天,下面是我的代码。
SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
csb.DataSource = @"CPX-XSYPQKSA91D\SQLEXPRESS";
csb.InitialCatalog = "DNN_Database";
csb.IntegratedSecurity = true;
string connString = csb.ToString();
string queryString = "select * FROM UserDefinedSectionData WHERE SectionDataTabId = @tabId";
using (SqlConnection connection = new SqlConnection(connString))
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = queryString;
command.Parameters.Add(new SqlParameter("tabId", tabId));
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
string sectionData= reader["SectionDatatable"].ToString();
int moduleId = Int32.Parse(reader["SectionDataModuleId"].ToString());
}
}
}
【问题讨论】:
-
为什么你使用 UserDefinedSectionData 作为表,虽然你提到它是一个列?什么是表名和列名?
-
@GaurangDave 很抱歉,我已经更正了。 SectionDatatable 是来自 UserDefinedSectionData 表的列
-
在下面查看我的答案。希望对您有所帮助。
标签: c# asp.net sql-server xml sqlconnection