我目前正在使用带有变量的存储过程从数据库中获取数据,但我是以 XML 格式返回结果。我可以使用此存储过程从表中获取所有数据,并以 XML 形式返回:
public string GetAllPatients()
{
string conn = @"Data Source=SNICKERS\SQLEXPRESS;Initial Catalog=VerveDatabase;Integrated Security=True";
DataSet oDS = new DataSet();
SqlDataAdapter oCMD = new SqlDataAdapter("getAll", conn);
oCMD.Fill(oDS, "AllPatients");
return oDS.GetXml();
}
但是,当我尝试获取个人患者记录并以 XML 格式返回时,我不确定如何,我目前正在这样做:
public void getUser(int ParticipantID)
{
SqlConnection oConn = new SqlConnection();
oConn.ConnectionString = @"Data Source=SNICKERS\SQLEXPRESS;Initial Catalog=VerveDatabase;Integrated Security=True";
oConn.Open();
DataSet oDS = new DataSet();
SqlCommand cmd = new SqlCommand();
cmd.Connection = oConn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "getUser";
cmd.Parameters.Add(new SqlParameter("@ParticipantID",SqlDbType.Int));
cmd.Parameters["@ParticipantID"].Value = 1;
SqlDataReader dr = cmd.ExecuteReader();
}