Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Articles
Search: 

Bonnie Berent's Tips
Bonnie DeWitt, July 1, 2006
Great tips for .NET developers
Summary
Great tips for .NET developers
Description

What's That Connection String?
Here's a great place to look for that hard-to-find connection string:

www.connectionstrings.com

They've got connection strings for everything from SQL Server, to Oracle, to Sybase, to stuff I've never heard of before. Check it out.

from a solution provided by Al Doman in Message #1051811

Collection Parameters
How does one go about setting up a property in a class that can be used to hold OleDbParameters (or SqlParameters ... same concept)? The first thought is to use the OleDbParametersCollection class, but that is a collection that cannot be instantiated. In other words, the following will not compile:
Public oParameters As New OleDbParameterCollection

Instead, use a simple Collection class. Here's an example:
Imports System.Data.OleDb

Public Class Library2

   Public oParameters As New Collection

   Public Function SQLExecCommand(ByVal cSQL As String) As OleDbCommand

      Dim ExecCmd As New OleDbCommand
      ExecCmd.Connection = Library.GetConnectionObject
      ExecCmd.CommandText = cSQL
      Dim oParam As OleDbParameter
      For Each oParam In oParameters
         ExecCmd.Parameters.Add(oParam)
      Next
      Return ExecCmd
   End Function
End Class

And here's how you might use this class and method:
Public Shared Function GetOrdersByEmployeeAndCustomer(ByVal EmployeeID As Integer, _
 ByVal CustomerId As String) As DataSet
      Dim oLib As New Library2
      oLib.oParameters.Add(New OleDbParameter("@EmployeeID", EmployeeID))
      oLib.oParameters.Add(New OleDbParameter("@CustomerID", CustomerId))

      Dim FoxCMD As OleDbCommand = oLib.SQLExecCommand("Select * From orders "+ _
       "where employeeID = ? and CustomerID = ? ")

      Dim FoxAdapter As New OleDbDataAdapter
      FoxAdapter.SelectCommand = FoxCMD

      Dim ReturnData As New DataSet
      FoxAdapter.Fill(ReturnData, "orders")

      FoxCMD.Connection.Close()

      Return ReturnData


   End Function

from a solution provided by Rod Paddock in Message #1080649

Mixing Classic ASP and ASP.NET
If you have old Classic ASP pages, you can still develop new pages using ASP.NET. They can call each other without problems. However, if you need to share state between the two, then you need a workaround. This article shows you how to do it:

http://www.asp101.com/articles/sidney/sharingsessionstate/default.asp

from a solution provided by Victor Campos in Message #1053517

Capturing Keystrokes in a DataGrid (WinForm)
The DataGrid on a WinForm doesn't raise the standard keystroke events under all conditions. If you need to handle key press events, you have to override the ProcessCmdKey method in your DataGrid sub-class ... see this article for more information:

http://www.codeproject.com/cs/database/DatabaseAcessWithAdoNet1.asp#Keystrokes

Here's an excerpt from the article, along with the code:

9. How to trap keystrokes (Up, Down, Esc, NumLock...) in the DataGrid

Like many users, I also looked for a method to catch the keystrokes in a DataGrid, and encountered it first in MSDN Library. So I decided to include it in the code so that users can make use of it. For most purposes, the standard KeyUp, KeyDown, and KeyPress events can capture and handle keystrokes. However, not all controls raise the standard KeyUp, KeyDown events for all keystrokes under all conditions. The DataGrid control is one of them.

If no data was assigned to the grid, the arrow keys (LEFT, RIGHT, UP, and DOWN) raise only the KeyUp event. If the DataGrid displays data, none of the standard keyboard events are raised for the navigation keys. The DataGrid is the control for which this feature is most frequently requested. You also can intercept key combinations, including CTRL and ALT. This technique does not capture the Print Screen key. In order to trap keystrokes in a Windows Forms control, you can override the ProcessCmdKey method ....

// Put this code in your Grid sub-class:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
	const int WM_KEYDOWN = 0x100;
	const int WM_SYSKEYDOWN = 0x104;

	if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
	{
		switch(keyData)
		{
			case Keys.Enter:
				MessageBox.Show("Enter");
				break;

			case Keys.Down:
				MessageBox.Show("Down");
				break;

			case Keys.Up:
				MessageBox.Show("Up");
				break;

			case Keys.NumLock:
				MessageBox.Show("NumLock");
				break;

			case Keys.Escape:
				MessageBox.Show("Escape");
				break;

		} 
	}

	return base.ProcessCmdKey(ref msg,keyData);
}

from a solution provided by Bonnie Berent in Message #1055291

Bonnie DeWitt, Geneva Systems Group
Bonnie is currently one of the principals of Geneva Systems Group. Call her the Senior Software Engineer, or even call her the VP of Engineering. She has no official title at the moment. Bonnie has been writing software in various languages for about 30 years. Bonnie's current focus on C# .NET applications began in early 2002. She has been a Microsoft C# MVP since Oct 2003 and an active member of the .NET online community.
More articles from this author
Bonnie DeWitt, September 1, 2005
Great tips for .NET developers
Bonnie DeWitt, October 1, 2005
Great tips for .NET developers
Bonnie DeWitt, November 1, 2005
Great tips for .NET developers
Bonnie DeWitt, December 1, 2005
Great tips for .NET developers
Bonnie DeWitt, April 1, 2009
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, February 1, 2006
Great tips for .NET developers
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers
Bonnie DeWitt, April 1, 2006
Great tips for .NET developers
Bonnie DeWitt, May 1, 2006
Great tips for .NET developers
Bonnie DeWitt, June 1, 2006
Great tips for .NET developers
Bonnie DeWitt, August 1, 2006
Great tips for .NET developers
Bonnie DeWitt, September 1, 2006
Great tips for .NET developers
Bonnie DeWitt, October 1, 2006
Great tips for .NET developers
Bonnie DeWitt, November 1, 2006
Great tips for .NET developers
Bonnie DeWitt, December 1, 2006
Great tips for .NET developers
Bonnie DeWitt, January 1, 2007
Great tips for .NET developers
Bonnie DeWitt, February 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers.
Bonnie DeWitt, April 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2007
Good tips for .NET developers.
Bonnie DeWitt, May 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, June 1, 2007
Great tips and tricks for .NET developers.
Bonnie DeWitt, July 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, August 1, 2007
Great tips for .NET developers
Bonnie DeWitt, September 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, February 1, 2008
Great tips from the Universal Thread .NET community.
Bonnie DeWitt, March 1, 2008
Great tips for .NET developers selected from the community by Bonnie Berent.
Bonnie DeWitt, April 1, 2008
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, January 1, 2006
Great tips for .NET developers