|
C SHARP |
| Top 8 Resources | |
| Resource | CSharpFriends.com |
| Resource | VB.Net and C# Comparison |
| Resource | Developing Windows Applications in C# - Stored Procedures |
| Resource | DevCity.Net - Visual Inheritance |
| Resource | FarelBoy.com |
| Resource | SQL Connection Code |
| Resource | CodeSmith |
| Resource | Ned Comp Hosting - DataRelations |
| Quick Reference | |
| Code | |
| Combo Box/
Storedprocedure
|
Add declarations below to the form class SqlConnection Con ; SqlCommand cmd, cmdSp; SqlDataAdapter da; DataSet ds; DataColumn parentCol; DataColumn childCol; DataRelation relEmpTer; DataView dv;
============================= Stored procedure in Northwind ======================= CREATE PROCEDURE getEmpName AS Select EmployeeId, FirstName+' '+LastName as FirstName from Employees GO
|
| :ATL LIBRARY - Example |
To create the example C# .NET Class Library: ------------------------------------------------------------------ 1) Open Visual Studio .NET 2003. 2) Open the File menu, click New, and select Project. 3) In "Project Types", click "C# Projects", and then click to select "Class Library". 4) Specify MyCSClassLib for the name, and click the OK button. 5) A "Class1.cs" editor window will be opened; close this window. 6) Open Solution Explorer, right-click Class1.cs and select Delete. Click the OK button when you are prompted that it will be permanently deleted. 7) Open the Project menu and select "Properties". 8) In the MyCSClassLib Property Pages dialog, click "Configuration Properties" and then click "Build". 9) Set "Register for COM Interop" to True and then click the OK button to close the properites dialog. 10) Open Solution Explorer again, right-click the MyCSClassLib project (not the "Solution..."), and select Add and "Add Class". 11) Specify "MyClass.cs" for the name and click the Open button. This will open a MyClass.cs editor window for the class. 12) At the top of this file, under the "using System;" statement, add the following statement:
using System.Runtime.InteropServices;
13) Change the MyClass constructor to look like the following:
public MyClass() { myHeight = 1; myWidth = 1;
myTestString = "This is a string value";
CalcArea(); }
14) Add the following code to the MyClass class body:
private double myHeight; private double myWidth; private double myArea;
public double Height { get { return myHeight; } set { myHeight = value; CalcArea(); } }
public double Width { get { return myWidth; } set { myWidth = value; CalcArea(); } }
public void CalcArea() { myArea = myWidth * myHeight; }
// John, here's an example of exporting a string. private string myTestString; public string TestString { get { return myTestString; } set { myTestString = value; } }
15) Build the solution (Build menu, select "Rebuild Solution").
16) Access this from VB6 by choosing References from the Project menu, and then placing a check mark next to "MyCSClassLib", adding a button to the Form1, and adding the following code into
the Command1_Click event handler:
Dim obj As MyCSClassLib.MyClass Set obj = New MyCSClassLib.MyClass
obj.Height = 25.4 obj.Width = 72.3
MsgBox "For height = " + CStr(obj.Height) + " and width = " + CStr(obj.Width) + ", the area = " + CStr(obj.Area)
MsgBox "The TestString from MyCSClassLib.MyClass = " + obj.TestString
17) Run the vb6 app by pressing the F5 key. |