C#Éú³Écom×é¼þ£¬¹©aspµ÷ÓÃ
Ò»¡¢vs2005—н¨ÏîÄ¿—C#Àà¿â
Àà¿âÔ´ÂëÈçÏÂ(°üº¬½Ó¿Ú£¬À࣬ʼþ½Ó¿Ú)£º
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
namespace entryclass
{
//GuidÖµµÄ²úÉú£ºProgram FilesMicrosoft Visual Studio 8Common7Toolsguidgen.exe£¬ÔËÐÐËü£¬Ñ¡Öе¥Ñ¡4£¬µã“New Guid”£¬µã“Copy”£¬½øÈëÀà¿â£¬Õ³Ìù¼´¿É
//Àà½Ó¿Ú
[Guid("F2257E71-ECC9-47ef-A065-F5B530F24B07")]
public interface ini_mng_Interface
{
[DispId(1)] //¹Ì¶¨Ð´·¨£¬Ë÷ÒýºÅ´Ó1¿ªÊ¼
string ini_dme(string entryuser, string entrypass, string agentname, str ......
C#Éú³Écom×é¼þ£¬¹©aspµ÷ÓÃ
Ò»¡¢vs2005—н¨ÏîÄ¿—C#Àà¿â
Àà¿âÔ´ÂëÈçÏÂ(°üº¬½Ó¿Ú£¬À࣬ʼþ½Ó¿Ú)£º
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
namespace entryclass
{
//GuidÖµµÄ²úÉú£ºProgram FilesMicrosoft Visual Studio 8Common7Toolsguidgen.exe£¬ÔËÐÐËü£¬Ñ¡Öе¥Ñ¡4£¬µã“New Guid”£¬µã“Copy”£¬½øÈëÀà¿â£¬Õ³Ìù¼´¿É
//Àà½Ó¿Ú
[Guid("F2257E71-ECC9-47ef-A065-F5B530F24B07")]
public interface ini_mng_Interface
{
[DispId(1)] //¹Ì¶¨Ð´·¨£¬Ë÷ÒýºÅ´Ó1¿ªÊ¼
string ini_dme(string entryuser, string entrypass, string agentname, str ......
ÕâÁ½¸öÊý¾ÝÀàÐÍÊÇÎÒÃÇÔÚѧϰC#ÓïÑԵĹý³ÌÖÐÊý¾Ý±È½ÏÄѵÄÁ½¸öÊý¾ÝÀàÐÍ£¬²»¹ýËûÃǺÜÖØÒª£¬ËùÒÔÓбØÒªÄóöÀ´ËµËµËûÃǵÄʹÓ÷½·¨ºÍ²»Í¬Ö®´¦£¬Ï£Íû¶ÔÄãÓÐËù°ïÖú¡£
ÏÈ×ܵÄÀ´Ëµ£º
ͨ³£ÎÒÃÇÏò·½·¨Öд«µÝµÄÊÇÖµ.·½·¨»ñµÃµÄÊÇÕâЩֵµÄÒ»¸ö¿½±´,È»ºóʹÓÃÕâЩ¿½±´,µ±·½·¨ÔËÐÐÍê±Ïºó,ÕâЩ¿½±´½«±»¶ªÆú,¶øÔÀ´µÄÖµ²»½«Êܵ½Ó°Ïì.´ËÍâÎÒÃÇ»¹ÓÐÆäËûÏò·½·¨´«µÝ²ÎÊýµÄÐÎʽ,ÒýÓÃ(ref)ºÍÊä³ö(out).
ÓÐʱ,ÎÒÃÇÐèÒª¸Ä±äÔÀ´±äÁ¿ÖеÄÖµ,Õâʱ,ÎÒÃÇ¿ÉÒÔÏò·½·¨´«µÝ±äÁ¿µÄÒýÓÃ,¶ø²»ÊDZäÁ¿µÄÖµ.ÒýÓÃÊÇÒ»¸ö±äÁ¿,Ëû¿ÉÒÔ·ÃÎÊÔÀ´±äÁ¿µÄÖµ,ÐÞ¸ÄÒýÓý«ÐÞ¸ÄÔÀ´±äÁ¿µÄÖµ.±äÁ¿µÄÖµ´æ´¢ÔÚÄÚ´æÖÐ,¿ÉÒÔ´´½¨Ò»¸öÒýÓÃ,ËûÖ¸Ïò±äÁ¿ÔÚÄÚ´æÖеÄλÖÃ.µ±ÒýÓñ»ÐÞ¸Äʱ,Ð޸ĵÄÊÇÄÚ´æÖеÄÖµ,Òò´Ë±äÁ¿µÄÖµ¿ÉÒÔ½«±»ÐÞ¸Ä.µ±ÎÒÃǵ÷ÓÃÒ»¸öº¬ÓÐÒýÓòÎÊýµÄ·½·¨Ê±,·½·¨ÖеIJÎÊý½«Ö¸Ïò±»´«µÝ¸ø·½·¨µÄÏàÓ¦±äÁ¿,Òò´Ë,ÎÒÃÇ»áÃ÷°×,Ϊʲôµ±Ð޸IJÎÊý±äÁ¿µÄÐÞ¸ÄÒ²½«µ¼ÖÂÔÀ´±äÁ¿µÄÖµ.
RefÖ¸Ã÷ÁË·½·¨ÖÐʹÓõÄÊÇÒýÓÃÐͲÎÊý£¬ÒýÓÃÐͲÎÊý²»¿ª±ÙеÄÄÚ´æÇøÓò¡£µ±ÀûÓÃÒýÓÃÐͲÎÊýÏò·½·¨´«µÝÐβÎʱ£¬±àÒë³ÌÐò½«°Ñʵ¼ÊÖµÔÚÄÚ´æÖеĵØÖ·´«µÝ¸Ã·½·¨¡£ÒýÓÃÐͲÎÊýͨ³£ÒѾ³õʼ»¯¡£
Èç
int i=1,j=2;//³õʼ»¯ &n ......
ÕâÁ½¸öÊý¾ÝÀàÐÍÊÇÎÒÃÇÔÚѧϰC#ÓïÑԵĹý³ÌÖÐÊý¾Ý±È½ÏÄѵÄÁ½¸öÊý¾ÝÀàÐÍ£¬²»¹ýËûÃǺÜÖØÒª£¬ËùÒÔÓбØÒªÄóöÀ´ËµËµËûÃǵÄʹÓ÷½·¨ºÍ²»Í¬Ö®´¦£¬Ï£Íû¶ÔÄãÓÐËù°ïÖú¡£
ÏÈ×ܵÄÀ´Ëµ£º
ͨ³£ÎÒÃÇÏò·½·¨Öд«µÝµÄÊÇÖµ.·½·¨»ñµÃµÄÊÇÕâЩֵµÄÒ»¸ö¿½±´,È»ºóʹÓÃÕâЩ¿½±´,µ±·½·¨ÔËÐÐÍê±Ïºó,ÕâЩ¿½±´½«±»¶ªÆú,¶øÔÀ´µÄÖµ²»½«Êܵ½Ó°Ïì.´ËÍâÎÒÃÇ»¹ÓÐÆäËûÏò·½·¨´«µÝ²ÎÊýµÄÐÎʽ,ÒýÓÃ(ref)ºÍÊä³ö(out).
ÓÐʱ,ÎÒÃÇÐèÒª¸Ä±äÔÀ´±äÁ¿ÖеÄÖµ,Õâʱ,ÎÒÃÇ¿ÉÒÔÏò·½·¨´«µÝ±äÁ¿µÄÒýÓÃ,¶ø²»ÊDZäÁ¿µÄÖµ.ÒýÓÃÊÇÒ»¸ö±äÁ¿,Ëû¿ÉÒÔ·ÃÎÊÔÀ´±äÁ¿µÄÖµ,ÐÞ¸ÄÒýÓý«ÐÞ¸ÄÔÀ´±äÁ¿µÄÖµ.±äÁ¿µÄÖµ´æ´¢ÔÚÄÚ´æÖÐ,¿ÉÒÔ´´½¨Ò»¸öÒýÓÃ,ËûÖ¸Ïò±äÁ¿ÔÚÄÚ´æÖеÄλÖÃ.µ±ÒýÓñ»ÐÞ¸Äʱ,Ð޸ĵÄÊÇÄÚ´æÖеÄÖµ,Òò´Ë±äÁ¿µÄÖµ¿ÉÒÔ½«±»ÐÞ¸Ä.µ±ÎÒÃǵ÷ÓÃÒ»¸öº¬ÓÐÒýÓòÎÊýµÄ·½·¨Ê±,·½·¨ÖеIJÎÊý½«Ö¸Ïò±»´«µÝ¸ø·½·¨µÄÏàÓ¦±äÁ¿,Òò´Ë,ÎÒÃÇ»áÃ÷°×,Ϊʲôµ±Ð޸IJÎÊý±äÁ¿µÄÐÞ¸ÄÒ²½«µ¼ÖÂÔÀ´±äÁ¿µÄÖµ.
RefÖ¸Ã÷ÁË·½·¨ÖÐʹÓõÄÊÇÒýÓÃÐͲÎÊý£¬ÒýÓÃÐͲÎÊý²»¿ª±ÙеÄÄÚ´æÇøÓò¡£µ±ÀûÓÃÒýÓÃÐͲÎÊýÏò·½·¨´«µÝÐβÎʱ£¬±àÒë³ÌÐò½«°Ñʵ¼ÊÖµÔÚÄÚ´æÖеĵØÖ·´«µÝ¸Ã·½·¨¡£ÒýÓÃÐͲÎÊýͨ³£ÒѾ³õʼ»¯¡£
Èç
int i=1,j=2;//³õʼ»¯ &n ......
1. ³ÌÐòÈçÏ£º
string str = "Create Database " + "DBname";
string con = "Data Source=10.0.0.249\\sql2005;Initial Catalog=master;Persist Security Info=True;User ID=sa;Password=sa";
SqlConnection myConn = new SqlConnection(con);
SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
Console.WriteLine("SQL Ó ......
1. ³ÌÐòÈçÏ£º
string str = "Create Database " + "DBname";
string con = "Data Source=10.0.0.249\\sql2005;Initial Catalog=master;Persist Security Info=True;User ID=sa;Password=sa";
SqlConnection myConn = new SqlConnection(con);
SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
Console.WriteLine("SQL Ó ......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient; //ÒýÓÃÃüÃû¿Õ¼ä
namespace DAL
{
/*******************************************************************************
* Name: SQLHelper
* File: SQLHelper.cs
* Description: ÓÃÓÚÍê³É¶ÔÊý¾Ý¿âµÄÏà¹Ø²Ù×÷
* Author: Ñ©ÀÇ
* DateTime: 2010Äê05ÔÂ13ÈÕ
*******************************************************************************/
public class SQLHelper
{
//ÉèÖÃÁ¬½Ó×Ö·û´® —— SQL ServerÑé֤ģʽµÄÁ¬½Ó×Ö·û´®
//public static string strConn = @"server = PANLING;database = StudentMIS;uid = sa;pwd = sa";
//ÉèÖÃÁ¬½Ó×Ö·û´® —— Windo ......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient; //ÒýÓÃÃüÃû¿Õ¼ä
namespace DAL
{
/*******************************************************************************
* Name: SQLHelper
* File: SQLHelper.cs
* Description: ÓÃÓÚÍê³É¶ÔÊý¾Ý¿âµÄÏà¹Ø²Ù×÷
* Author: Ñ©ÀÇ
* DateTime: 2010Äê05ÔÂ13ÈÕ
*******************************************************************************/
public class SQLHelper
{
//ÉèÖÃÁ¬½Ó×Ö·û´® —— SQL ServerÑé֤ģʽµÄÁ¬½Ó×Ö·û´®
//public static string strConn = @"server = PANLING;database = StudentMIS;uid = sa;pwd = sa";
//ÉèÖÃÁ¬½Ó×Ö·û´® —— Windo ......
C#ÖжÔbaseµÄ½âÊÍ(Òý×ÔMSDN):
base ¹Ø¼ü×ÖÓÃÓÚ´ÓÅÉÉúÀàÖзÃÎÊ»ùÀàµÄ³ÉÔ±£º
µ÷ÓûùÀàÉÏÒѱ»ÆäËû·½·¨ÖØдµÄ·½·¨¡£
Ö¸¶¨´´½¨ÅÉÉúÀàʵÀýʱӦµ÷ÓõĻùÀ๹Ô캯Êý¡£
»ùÀà·ÃÎÊÖ»ÄÜÔÚ¹¹Ô캯Êý¡¢ÊµÀý·½·¨»òʵÀýÊôÐÔ·ÃÎÊÆ÷ÖнøÐС£
´Ó¾²Ì¬·½·¨ÖÐʹÓà base ¹Ø¼ü×ÖÊÇ´íÎóµÄ¡£
ÔÚ±¾ÀýÖУ¬»ùÀà Person ºÍÅÉÉúÀà Employee ¶¼ÓÐÒ»¸öÃûΪ Getinfo µÄ·½·¨¡£Í¨¹ýʹÓà base ¹Ø¼ü×Ö£¬¿ÉÒÔ´ÓÅÉÉúÀàÖе÷ÓûùÀàµÄ Getinfo ·½·¨¡£
public class Person
{
protected string ssn = "444-55-6666";
protected string name = "John L. Malgraine";
public virtual void GetInfo()
{
Console.WriteLine("Name: {0}", name);
Console.WriteLine("SSN: {0}", ssn);
}
}
class Employee : Person
{
public string id = "ABC567EFG";
public override void GetInfo()
{
// Calling the ......
C#ÖжÔbaseµÄ½âÊÍ(Òý×ÔMSDN):
base ¹Ø¼ü×ÖÓÃÓÚ´ÓÅÉÉúÀàÖзÃÎÊ»ùÀàµÄ³ÉÔ±£º
µ÷ÓûùÀàÉÏÒѱ»ÆäËû·½·¨ÖØдµÄ·½·¨¡£
Ö¸¶¨´´½¨ÅÉÉúÀàʵÀýʱӦµ÷ÓõĻùÀ๹Ô캯Êý¡£
»ùÀà·ÃÎÊÖ»ÄÜÔÚ¹¹Ô캯Êý¡¢ÊµÀý·½·¨»òʵÀýÊôÐÔ·ÃÎÊÆ÷ÖнøÐС£
´Ó¾²Ì¬·½·¨ÖÐʹÓà base ¹Ø¼ü×ÖÊÇ´íÎóµÄ¡£
ÔÚ±¾ÀýÖУ¬»ùÀà Person ºÍÅÉÉúÀà Employee ¶¼ÓÐÒ»¸öÃûΪ Getinfo µÄ·½·¨¡£Í¨¹ýʹÓà base ¹Ø¼ü×Ö£¬¿ÉÒÔ´ÓÅÉÉúÀàÖе÷ÓûùÀàµÄ Getinfo ·½·¨¡£
public class Person
{
protected string ssn = "444-55-6666";
protected string name = "John L. Malgraine";
public virtual void GetInfo()
{
Console.WriteLine("Name: {0}", name);
Console.WriteLine("SSN: {0}", ssn);
}
}
class Employee : Person
{
public string id = "ABC567EFG";
public override void GetInfo()
{
// Calling the ......
ÏÂÃæÕâ¶ÎC# ´úÂë¿ÉÒÔÓÃÀ´Ñ¹ËõºÍÐÞ¸´AccessÊý¾Ý¿â,²»¹ÜËüÊÇÒ»¸ö¼òµ¥µÄ".mdb"ACCESSÊý¾Ý¿â»¹ÊÇÒ»¸ö".mdw"ÍøÂç¹²ÏíÊý¾Ý¿â,Õâ¸ö¹ý³ÌºÍÄãÔÚÓÃMS AccessÓ¦ÓóÌÐòÖÐʹÓõÄ"¹¤¾ß-Êý¾Ý¿âʵÓù¤¾ß-ѹËõºÍÐÞ¸´"ʱִÐеIJÙ×÷ÍêÈ«Ò»Ñù.ʵÀý´úÂëʹÓÃÁË"³Ù°ó¶¨"(ÔËÐÐÖÐÔÚÄÚ´æÖн¨Á¢COM¶ÔÏó),ÕâÑù¾Í²»ÐèÒªÔÚ¹¤³ÌÖмÓÈëCOMÒýÓÃÁË,Ò²²»ÐèÒªÔÚPCÉÏ°²×°MS AccessÓ¦ÓóÌÐò.Ö»ÐèÒªÒ»¸öJetÒýÇæ(JetÒýÇæ°üº¬ÔÚMDAC°²×°°üÖÐ,ÔÚWindows NT4ÒÔºóµÄ°æ±¾ÖÐ,ϵͳÒѾ×Ô´øÁËÕâ¸öÒýÇæ).
C#²Ù×÷ACCESSÊý¾Ý¿âµÄ±³¾°
²»ÖªÄãÊÇ·ñÒ²Ñá·³ÁËÔÚ¹¤³ÌÖмÓÈ븴ÔÓµÄCOM¿âÒýÓÃ,µ«ÎÒÏàÐÅÕâ¸ö´¿.NET´úÂ뽫ʡȥ¶îÍâµÄ½»»¥²Ù×÷, RCWsºÍCOMÒýÓÃ.»ù±¾ÉÏ,ÓÉÓÚϵͳÖа²×°µÄMicrosoftÀà¿âµÄ²»Í¬(ÀýÈç:MS Office Object Library 9,10,11µÈµÈ),ÎÒÃÇÒ²²»ÖªµÀÓû§PCÖа²×°µÄOffice°æ±¾,ËùÒÔÎÒÃÇҪͨ¹ýProgIDÀ´·ÃÎÊCOM¶ÔÏó,¶ø²»ÄÜÓÃCLSID.ÀýÈç,µ±µ÷ÓÃ"Excel.Application",ʱ,µÃµ½µÄÊÇExcel,¶ø²»¹ÜϵͳÖа²×°MS OfficeµÄ°æ±¾,µ±ÔÚ´úÂëÖмÓÈë"MS Excel 10 Object library"ÒýÓÃʱ,ÆäʵֻÊǸøÓ¦ÓóÌÐò¼ÓÈëÁËÒ»¸ö·Ç³£ÊÜÏÞÖƵŦÄÜ.ËùÒÔÎÒÃÇʹÓÃSystem.ReflectionºÍ³Ù°ó¶¨.
1. ʵÀý´úÂë
Ö»Ðèµ÷ÓÃCompactAccessDBº¯Êý¼´¿ÉѹËõºÍÐÞ¸´Ä¿±êÊý¾Ý¿â ......
ÏÂÃæÕâ¶ÎC# ´úÂë¿ÉÒÔÓÃÀ´Ñ¹ËõºÍÐÞ¸´AccessÊý¾Ý¿â,²»¹ÜËüÊÇÒ»¸ö¼òµ¥µÄ".mdb"ACCESSÊý¾Ý¿â»¹ÊÇÒ»¸ö".mdw"ÍøÂç¹²ÏíÊý¾Ý¿â,Õâ¸ö¹ý³ÌºÍÄãÔÚÓÃMS AccessÓ¦ÓóÌÐòÖÐʹÓõÄ"¹¤¾ß-Êý¾Ý¿âʵÓù¤¾ß-ѹËõºÍÐÞ¸´"ʱִÐеIJÙ×÷ÍêÈ«Ò»Ñù.ʵÀý´úÂëʹÓÃÁË"³Ù°ó¶¨"(ÔËÐÐÖÐÔÚÄÚ´æÖн¨Á¢COM¶ÔÏó),ÕâÑù¾Í²»ÐèÒªÔÚ¹¤³ÌÖмÓÈëCOMÒýÓÃÁË,Ò²²»ÐèÒªÔÚPCÉÏ°²×°MS AccessÓ¦ÓóÌÐò.Ö»ÐèÒªÒ»¸öJetÒýÇæ(JetÒýÇæ°üº¬ÔÚMDAC°²×°°üÖÐ,ÔÚWindows NT4ÒÔºóµÄ°æ±¾ÖÐ,ϵͳÒѾ×Ô´øÁËÕâ¸öÒýÇæ).
C#²Ù×÷ACCESSÊý¾Ý¿âµÄ±³¾°
²»ÖªÄãÊÇ·ñÒ²Ñá·³ÁËÔÚ¹¤³ÌÖмÓÈ븴ÔÓµÄCOM¿âÒýÓÃ,µ«ÎÒÏàÐÅÕâ¸ö´¿.NET´úÂ뽫ʡȥ¶îÍâµÄ½»»¥²Ù×÷, RCWsºÍCOMÒýÓÃ.»ù±¾ÉÏ,ÓÉÓÚϵͳÖа²×°µÄMicrosoftÀà¿âµÄ²»Í¬(ÀýÈç:MS Office Object Library 9,10,11µÈµÈ),ÎÒÃÇÒ²²»ÖªµÀÓû§PCÖа²×°µÄOffice°æ±¾,ËùÒÔÎÒÃÇҪͨ¹ýProgIDÀ´·ÃÎÊCOM¶ÔÏó,¶ø²»ÄÜÓÃCLSID.ÀýÈç,µ±µ÷ÓÃ"Excel.Application",ʱ,µÃµ½µÄÊÇExcel,¶ø²»¹ÜϵͳÖа²×°MS OfficeµÄ°æ±¾,µ±ÔÚ´úÂëÖмÓÈë"MS Excel 10 Object library"ÒýÓÃʱ,ÆäʵֻÊǸøÓ¦ÓóÌÐò¼ÓÈëÁËÒ»¸ö·Ç³£ÊÜÏÞÖƵŦÄÜ.ËùÒÔÎÒÃÇʹÓÃSystem.ReflectionºÍ³Ù°ó¶¨.
1. ʵÀý´úÂë
Ö»Ðèµ÷ÓÃCompactAccessDBº¯Êý¼´¿ÉѹËõºÍÐÞ¸´Ä¿±êÊý¾Ý¿â ......