把下面的这个简单的函数存储方式由数据库改为XML存储
如题 想把这个函数改成XML存储 可是XML相关操作语句不熟悉 请帮忙//获取指定Id的日程信息
public bool GetScheduleById(ref SqlConnection myConn, int ScheduleId)
{
SqlCommand cmd = new SqlCommand("GetScheduleById", myConn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(ScheduleId);
SqlDataReader ScheduleReader = cmd.ExecuteReader();
int tmpTaskId = 0;
string tmpTitle = "";
string tmpDetail = "";
DateTime tmpBeginTime = DateTime.Now;
DateTime tmpNotifyTime = DateTime.Now;
int tmpNeedNotify = 0;
int tmpFinished = 0;
int tmpType = 0;
int tmpPriority = 0;
try
{
if(ScheduleReader.Read())
{
tmpTaskId = Int32.Parse(ScheduleReader["TASK_ID"].ToString().Trim());
tmpTitle = ScheduleReader["Title"].ToString().Trim();
tmpDetail = ScheduleReader["Detail"].ToString().Trim();
tmpBeginTime = DateTime.Parse(ScheduleReader["BeginTime"].ToString());
tmpNotifyTime = DateTime.Parse(ScheduleReader["NotifyTime"].ToString());
tmpNeedNotify = Int32.Parse(ScheduleReader["NeedNotify"].ToString().Trim());
tmpFinished = Int32.Parse(ScheduleReader["Finished"].ToString().Trim());
tmpType = Int32.Parse(ScheduleReader["Type"].ToString().Trim());
tmpPriority = Int32.Parse(ScheduleReader["Priority"].ToString().Trim());
}
}
catch
{
ScheduleReader.Close();
return false;
}
TaskId = tmpTaskId;
Title = tmpTitle;
Detail = tmpDetail;
BeginTime = tmpBeginTime;
NotifyTime = tmpNotifyTime;
NeedNotify = tmpNeedNotify;
Finished = tmpFinished;
Type = tmpType;
Priority = tmpPriority;
return IsValidSchedule();
}
//获取指定日期的日程
public bool GetScheduleByGivenDay(ref SqlConnection myConn, ref DataSet ds, ref DateTime GivenDay)
{
SqlDataAdapter da = new SqlDataAdapter("GetScheduleByGivenDay", myConn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add("@GivenDay", GivenDay);
try
{
da.Fill(ds, "ScheduleList");
}
catch
{
return false;
}
return true;
}
//获取所有日程列表
public bool GetAllSchedule(ref SqlConnection myConn, ref DataSet ds)
{
SqlDataAdapter da = new SqlDataAdapter("GetAllSchedule", myConn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
try
{
da.Fill(ds, "ScheduleList");
}
catch
{
return false;
}
return true;
}
--------------------编程问答-------------------- up --------------------编程问答-------------------- 不会。。。
Up! --------------------编程问答-------------------- 仔细看下 非常简单的个函数 可能变量多点 可是都没什么大用啊! --------------------编程问答-------------------- 其实要改的就这么几句:
SqlCommand cmd = new SqlCommand("GetScheduleById", myConn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(ScheduleId);
SqlDataReader ScheduleReader = cmd.ExecuteReader();
--------------------编程问答-------------------- lz: 利用DataSet实现ADO.NET与XML的无缝连接:
1、DataSet.ReadXml 方法
2、DataSet.WriteXml 方法
代码实例:
private void DemonstrateReadWriteXMLDocumentWithStreamReader()
{
// Create a DataSet with one table and two columns.
DataSet OriginalDataSet = new DataSet("dataSet");
OriginalDataSet.Namespace= "NetFrameWork";
DataTable table = new DataTable("table");
DataColumn idColumn = new DataColumn("id",
Type.GetType("System.Int32"));
idColumn.AutoIncrement= true;
DataColumn itemColumn = new DataColumn("item");
table.Columns.Add(idColumn);
table.Columns.Add(itemColumn);
OriginalDataSet.Tables.Add(table);
// Add ten rows.
DataRow newRow;
for(int i = 0; i < 10; i++)
{
newRow = table.NewRow();
newRow["item"]= "item " + i;
table.Rows.Add(newRow);
}
OriginalDataSet.AcceptChanges();
// Print out values of each table in the DataSet
// using the function defined below.
PrintValues(OriginalDataSet, "Original DataSet");
// Write the schema and data to an XML file.
string xmlFilename = "XmlDocument.xml";
// Use WriteXml to write the document.
OriginalDataSet.WriteXml(xmlFilename);
// Dispose of the original DataSet.
OriginalDataSet.Dispose();
// Create a new DataSet.
DataSet newDataSet = new DataSet("New DataSet");
// Read the XML document into the DataSet.
newDataSet.ReadXml(xmlFilename);
// Print out values of each table in the DataSet
// using the function defined below.
PrintValues(newDataSet,"New DataSet");
}
private void PrintValues(DataSet dataSet, string label)
{
Console.WriteLine("\n" + label);
foreach(DataTable table in dataSet.Tables)
{
Console.WriteLine("TableName: " + table.TableName);
foreach(DataRow row in table.Rows)
{
foreach(DataColumn column in table.Columns)
{
Console.Write("\table " + row[column] );
}
Console.WriteLine();
}
}
}
补充:.NET技术 , C#