Posted by Brad | Posted in Recommendations | Posted on 29-12-2011
I fancy moving from windows 2003 to windows 2008 for my private VPS… trouble is I couldn’t remember the name of the host as I never have to contact them.. sites area always up!
After minutes of wrecking my brain… it’s EUKHost… give them a try then you will have nothing to worry about either
Posted by Brad | Posted in Ramblings | Posted on 05-12-2011
I’m constantly seeing references to PowerShell in Visual Studio 2010 related tutorials, today I came across this thing… PowerShell and HTML5, and would love to get your feedback on a proof-of-concept.
This prototype uses the System.Net.WebClient class to “bootstrap” itself, and from there, awesomenes ensues.
From a PowerShell prompt, run the following command:
iex (New-Object Net.WebClient).DownloadString(“http://bit.ly/e0Mw9w”)
Currently I use Console2 for my command prompt… might just have to change that now :)
Posted by Brad | Posted in C# | Posted on 06-07-2011
Need to bind a web control to an OleDb data source in your C# web application, here’s the magic. In this case I am binding a ListBox control with an ID of ListBox1 to the ProductName field in the Products table of our old friend the Northwind database.
These are the using statements that you need to apply including the ConfigurationManager to get your web.config connection string conveniently
using System.Data;
using System.Data.OleDb;
using System.Configuration;
Here is our class that does all the work
protected void DataSetFromOleDbDemo()
{
string strSQL = "SELECT * FROM Products WHERE CategoryID = 1";
var conString = ConfigurationManager.ConnectionStrings["Northwind"];
string Conn = conString.ConnectionString;
try
{
using (OleDbDataAdapter adapter = new OleDbDataAdapter(strSQL, Conn))
{
DataSet ds = new DataSet();
adapter.Fill(ds, "ProductInfo");
foreach (DataRow dr in ds.Tables["ProductInfo"].Rows)
{
ListBox1.Items.Add(dr["ProductName"].ToString());
}
}
}
catch (Exception)
{
throw;
}
}
And your OleDb connection string to put in the connectionStrings section of your web.config is as follows
<connectionStrings>
<add name="Northwind" connectionString="Provider=SQLOLEDB;server=YOURSERVER;database=Northwind;uid=USERNAME;password=PASSWORD;" />
</connectionStrings>
Posted by Brad | Posted in C#, Coding | Posted on 23-06-2009
Remember to add the usual using directives at the start of the codebehind
using System.Data;
using System.Data.SqlClient;
For a DropDownList on your ASP.NET page with an ID of Category such a
<asp:DropDownList ID="Category" runat="server">
</asp:DropDownList>
The following in your code behind will bind data from an example Northwind database on SQL Server to the text and values of the DropDownList
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace AppDevStuff
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using(SqlConnection cnn = new SqlConnection("Data Source=YOURSERVERNAME; Database=Northwind; UID=YOURUSERNAME; PWd=YOURPASSWORD"))
{
SqlCommand cmd;
SqlDataReader rdr;
if (!Page.IsPostBack)
{
cmd = new SqlCommand("SELECT CategoryID, CategoryName FROM Categories ORDER BY CategoryName;", cnn);
cnn.Open();
rdr = cmd.ExecuteReader();
Category.DataSource = rdr;
Category.DataTextField = "CategoryName";
Category.DataValueField = "CategoryID";
Category.DataBind();
}
}
}
}
}