I’m currently using a store procedure with a variable to get data from a database but I was the return the result in XML. I can get all data from a table using this store procedure and it returns in 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();
}
However when I try to get an idividual patient record and return it in XML I’m not sure how, I;m currently doing this:
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();
}
To get XML from SQL Server, your stored procedure needs to read something like
which will generate an XML result which you can then read with
EDIT on clarifications
Replace the datareader in the last line of your second procedure with code similar to your first