Having messed around for a good part of yesterday with trying to bind some values to a RadioButtonList control and failing miserably, I suddenly realised (after a quick check on MSDN) just how simple it really is.
// Set the properties of the radio button list.
rbl.DataSource = results.Tables[0].DefaultView;
rbl.DataTextField = "Name";
rbl.DataValueField = "ID";
rbl.DataBind();
So much wasted time, but a lesson learnt. Next time I'll consider that databinding might exist, before I come up with some crazy scheme involving Literals...
Thursday, September 15, 2005
Wednesday, January 05, 2005
Environment
string pathToLog = Environment.CurrentDirectory + "\\Config\\Rules.xml"; //was --> @"c:\temp\Log.txt";
Environment.CurrentDirectory
Environment.CurrentDirectory
Monday, November 29, 2004
"Cannot load type " - Fix
- Try killing asp_wp.exe
- Try deleting DLL and re-compiling (main app DLL)
- Try deleting virtual directory and setting up again. Also restart application.
- Delete anything in the temporary files (c:\program files\.NET, etc....). This usually requires killing off the worker process (asp_wp.exe)
Sunday, November 28, 2004
Using .NET in conjunction with SQLS' "FOR XML AUTO" option
If you want to manipulate raw XML data returned from SQLS with .NET, you'll need to use something like the following:
You could use something similar in conjunction with a stored proc also, using either XML AUTO, RAW or EXPLICIT options.
This will give you some nice raw xml data.
Then you can create some .NET code to fire off and return results from the stored proc.
You can then use these methods on your page, or within any higher business-level class.
XmlDocument doc = new XmlDocument();
using (SqlConnection conn = new SqlConnection("...")) {
SqlCommand cmd = new SqlCommand(@"SELECT 1 FOR XML AUTO", conn);
conn.Open();
doc.Load(cmd.ExecuteXmlReader());
conn.Close();
}
You could use something similar in conjunction with a stored proc also, using either XML AUTO, RAW or EXPLICIT options.
CREATE PROCEDURE sp_GetInfo
AS
SELECT 123 AS Tag, 0 As Parent, p_name AS [Person!123!p_name], p_add AS [Person!123!p_add]
FROM TBL_People_Info
FOR XML EXPLICIT
GO
This will give you some nice raw xml data.
Then you can create some .NET code to fire off and return results from the stored proc.
private SqlCommand BuildQueryCommand(string storedProcName,
IDataParameter[] parameters)
{
SqlCommand command =
new SqlCommand(storedProcName, Connection);
command.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter parameter in parameters)
{
command.Parameters.Add(parameter);
}
return command;
}
protected System.Xml.XmlDocument RunProcedure(string storedProcName, IDataParameter[] parameters)
{
System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
SqlCommand cmd = BuildQueryCommand(storedProcName, parameters);
Connection.Open();
xDoc.Load(cmd.ExecuteXmlReader());
Connection.Close();
return xDoc;
}
You can then use these methods on your page, or within any higher business-level class.
You're then free to do what you will with the data returned. Transform it, output it in raw form, etc.
System.Xml.XmlDocument xDoc = RunProcedure("sp_GetInfo", new IDataParameter[]{});
Subscribe to:
Posts (Atom)
Fixes to common .NET problems, as well as information on .NET features and solutions to common problems that are not language-specific.
Fixes to common .NET problems, as well as information on .NET features and solutions to common problems that are not language-specific.