(c) 2002 Visual Studio Magazine 
Fawcette Technical Publications

Issue: November 2002
Section: ASP.NET
Author: Don Kiely

C#, ADO.NET	Customize Web Matrix Code
Listing 1	Web Matrix mostly generated this fairly standard ADO.NET code. For the Events project, I had to first change the connection string to point to the correct database (and in a production app probably the authentication information). The code for the stored procedure and parameter also needed customization, to use the GetCalendarItems stored procedure and @OrgID parameter. Out of the box, Web Matrix plugs in generic information to access the Northwind database.

void Page_Load(object sender, EventArgs e)
	{
		string ConnectionString = 
			"server=(local);database=Clubs; 
			trusted_connection=true";

		string CommandText = "GetCalendarItems";

		SqlConnection myConnection = new 
			SqlConnection(ConnectionString);
		SqlCommand myCommand = new 
			SqlCommand(CommandText, myConnection);
		SqlParameter workParam;

		myCommand.CommandType = 
			CommandType.StoredProcedure;

		//Select an organization, since the 
    		//calendar supports any number 
		myCommand.Parameters.Add("@OrgID", 
			SqlDbType.Int).Value = 1;

		myConnection.Open();

		dgCalendar.DataSource = 
			myCommand.ExecuteReader
			(CommandBehavior.CloseConnection);
		dgCalendar.DataBind();
	}
