Monthly Archives: October 2004

Using XPath to narrow results from an XML file

// These two lines read config setting from the app.config file. filename = ConfigurationSettings.AppSettings["inputfile"]; filter = Configu rationSettings.AppSettings["filter1"]; XmlDataDocument myDocument = new XmlDataDocument(); myDocument.Load(filename); XmlNodeList myList = myDocument.SelectNodes(“//item[@class='" + filter + "']/*”); for (int i=0; i < myList.Count; i++) { … Continue reading

Posted in C# Snippets | Comments Off

Create a DataSet from a Stored Procedure

SqlConnection myConn = new SqlConnection(ConnectionString); SqlDataAdapter da = new SqlDataAdapter(); ds.SelectCommand = new SqlCommand(“GetByOffice”,myConn); da.SelectCommand.CommandType=CommandType.StoredProcedure; SqlParameter myParam = new SqlParameter(“@Office”,SqlDbType.VarChar,50); myParam.Direction=ParameterDirection.Input; myParam.Value = textBox1.Text; da.SelectCommand.Parameters.Add(myParam); DataSet ds = new DataSet(); da.Fill(ds,”results”); dataGrid1.DataSource = ds.Tables["Results"]; ds.WriteXml(“result.xml”,XmlWriteMode.WriteSchema);

Posted in C# Snippets | Comments Off