Android, Oracle, MS-SQL, PHP, JAVA, XML, C#, php, memcache, linux, centos6, mysql, mongodb
c# sealed keyword (block method overriding)
C#에서는 sealed 키워드, 자바에서는 final 키워드를 사용한다. C#과 C++ 같은 언어는 메소드가 기본적으로 봉인된 것으로 간주한다. virtual 키워드를 부여하여 봉인을 해제한다. 반면, 자바와 같은 언어에서는 기본적으로 메스도가 봉인되지 않다.
봉인이 바람직한 것인지에 대한 많은 논란이 있다. 지시에 따르는 태도(directing attitude)를 가진 이들은 재정의가 가능한 클래스나 기능(features)에 대해 매우 조심스러워서 안전할 것으로 간주된 것만 확장을 허용 한다. 개발자의 여지를 허용하는 태도(EnablingAttitude)를 가진 이들은 확장이 필요한 메소드와 그렇지 않을 것을 예측할 수 없다는 견해를 갖는다. 프로그래머가 원하면 어떤 메소드라도 재정의를 할 수 있는 대신에 책임감을 갖고 주의해야 한다. 대개 나는 후자의 태도 갖는다.
Dotnet Remoting 닷넷 리모팅 C#
자세한 설명등은 없습니다.
----------------- Actor Mode.cs----------------------
using System;
namespace VINS.ActMode
{
/// <summary>
/// IRC 서버 기본 모듈
/// </summary>
public class ActModeClass : MarshalByRefObject
{
string m_strString;
public ActModeClass()
{
Console.WriteLine("생성자가 호출 되었습니다");
}
public void AddString(string strStr)
{
m_strString += strStr;
Console.WriteLine(m_strString);
}
}
}
-------------- Actor Host.cs --------------------------
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
namespace CJIJ.ActHosting
{
/// <summary>
/// Class1에 대한 요약 설명입니다.
/// </summary>
class ActHostingClass
{
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//Http 1220을 이용하여 채널 등록
ChannelServices.RegisterChannel(new HttpChannel(1220));
/*
//######## 서버 활성화 모드 2가지 예제 #########
//1. Singleton 모드(원격 객체가 하나만 생성되고 모든 클라이언트에선 그 원격객체를 이용하기 때문에 정보를 공유할 수 있다)
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ActMode.ActModeClass), "ActModeUri", WellKnownObjectMode.Singleton);
//2. SingleCall 모드(클라이언트가 메셔드를 호출 할때 마다 원격 객체가 생성되고 메서드 호출과 호출 사이엔 객체의 상태가 유지 되지 않는다.)
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ActMode.ActModeClass), "ActModeUri", WellKnownObjectMode.SingleCall);
*/
//######## 클라이언트 활성화 모드 #########
RemotingConfiguration.RegisterActivatedServiceType(typeof(ActMode.ActModeClass));
RemotingConfiguration.ApplicationName = "ActModeApp";
//이용자의 알림 메세지
Console.WriteLine("호스팅 어플리케이션이 시작되었습니다");
Console.WriteLine("엔터키를 누르면 종료합니다.");
//대기모드로 들어간다.
Console.ReadLine();
}
}
}
-------------- Actor Client -----------------------
using System;
using CJIJ.ActMode;
using System.Runtime.Remoting; //ActHosting이 클라이언트 모드인 경우 선언해야 함
namespace ActClient
{
/// <summary>
/// ActClient Mode
/// </summary>
class ActClientClass
{
[STAThread]
static void Main(string[] args)
{
/*
//Acthosting 의 객체 활성화 모드가 서버 방식일때 사용
//원격 객체의 프록시 생성
ActModeClass obj = (ActModeClass)Activator.GetObject(typeof(CJIJ.ActMode.ActModeClass), "http://localhost:1220/ActModeUri");
*/
//Acthosting 의 객체 활성화 모드가 클라이언트 방식일때
RemotingConfiguration.RegisterActivatedClientType(typeof(CJIJ.ActMode.ActModeClass), "http://localhost:1220/ActModeApp");
CJIJ.ActMode.ActModeClass obj = new CJIJ.ActMode.ActModeClass();
//알림 메세지 표시
Console.WriteLine("끝내려면 /quit를 입력하세요");
while(true)
{
//유저로 부터 문자열을 받는다.
string strText = Console.ReadLine();
// "/quit" 문자열을 입력하면 프로그램을 종료시킨다.
if(strText == "/quit")
break;
//원격 객체의 메서드를 호출한다.
obj.AddString(strText);
}
}
}
}
MSMQ Control C#
using System.Text;
using System.Messaging;
using System.Collections;
using System.EnterpriseServices;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
public class CJIJMessageQueueForAD2 : ServicedComponent
{
public System.Messaging.MessageQueue msmq;
public CJIJMessageQueueForAD2()
{}
public string AdShoot(string mqTitle, string mqBody)
{
try
{
///Queue Check Logic
Adprepared();
//msmq = new System.Messaging.MessageQueue(@".\Private$\CJIJAdvertisement01");
}
catch(Exception e)
{
return "1-1 : " + e.Message + " / " + e.Source + " / " + e.InnerException + " / " + e.StackTrace + " / " + e.TargetSite + " / " + e.HelpLink;
}
try
{
System.Messaging.Message msgCue = new System.Messaging.Message();
msgCue.Body = mqBody.ToString();
msgCue.Label = mqTitle.ToString();
msgCue.AcknowledgeType = AcknowledgeTypes.PositiveArrival | AcknowledgeTypes.PositiveReceive;
msmq.Send(msgCue);
return "1-2 : Message Send Complete";
}
catch(Exception e)
{
return "1-2 : " + e.Message + " / " + e.Source + " / " + e.InnerException + " / " + e.StackTrace + " / " + e.TargetSite + " / " + e.HelpLink;
}
}
public string CreateMQ()
{
try
{
//if(MessageQueue.Exists("FormatName:DIRECT="+MQNameURL.ToString()))
//msmq = new System.Messaging.MessageQueue("FormatName:DIRECT="+MQNameURL.ToString());
msmq = new System.Messaging.MessageQueue(@".\Private$\CJIJAdvertisement02");
return "2-1 : MSMQ Create Complete";
}
catch(Exception e)
{
return "2-1 : " + e.Message + " / " + e.Source + " / " + e.InnerException + " / " + e.StackTrace + " / " + e.TargetSite + " / " + e.HelpLink;
}
}
public void Adprepared()
{
if(MessageQueue.Exists(@".\Private$\CJIJAdvertisement02"))
msmq = new System.Messaging.MessageQueue(@".\Private$\CJIJAdvertisement02");
else
msmq = MessageQueue.Create(@".\Private$\CJIJAdvertisement02");
}
}
MSMQ for Advertise C#
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data.Common;
using System.Messaging;
using System.Threading;
using System.Diagnostics;
using System.ServiceProcess;
using CJIJ.DataCore;
namespace CJIJ.AdverServer
{
public class AdverServerWinSvc : System.ServiceProcess.ServiceBase
{
///
/// 필수 디자이너 변수입니다.
///
private System.ComponentModel.Container components = null;
private System.Diagnostics.EventLog eventLog1;
private System.Timers.Timer timer1;
public System.Messaging.MessageQueue msmq;
public System.Messaging.Message msg;
//public businessLogic BOobj;
public AdverServerWinSvc()
{
// 이 호출은 Windows.Forms 구성 요소 디자이너에 필요합니다.
InitializeComponent();
timer1.Enabled = true;
timer1.Interval = 25;
timer1.Elapsed += new System.Timers.ElapsedEventHandler(MQReader);
// TODO: InitComponent를 호출한 다음 초기화 작업을 추가합니다.
}
// 프로세스의 주 진입점입니다.
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// 같은 프로세스 내에서 둘 이상의 사용자 서비스가 실행될 수 있습니다.
// 이 프로세스에 다른 서비스를 추가하려면 두 번째 서비스 개체를 만들도록
// 다음 줄을 변경합니다. 예를 들면 다음과 같습니다.
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new AdverServerWinSvc() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
///
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
///
private void InitializeComponent()
{
this.timer1 = new System.Timers.Timer();
this.eventLog1 = new System.Diagnostics.EventLog();
((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
//BOobj = new businessLogic("Data Source=210.174.197.113; Initial Catalog=Advertisement_Action; User Id=webaccount; Password=&dnpqdblog%^&");
//BOobj = new businessLogic("server=210.174.197.113; database=Advertisement_Action; uid=webaccount; pwd=&dnpqdblog%^&");
this.timer1.Enabled = true;
this.CanPauseAndContinue = true;
this.ServiceName = "CJIJ_Advertisement";
((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
MQPrepared();
}
public void MQReader(object sender, System.Timers.ElapsedEventArgs e)
{
msg = msmq.Receive(new TimeSpan(0,0,0,10));
msg.Formatter = new XmlMessageFormatter(new String[] {"System.String,mscorlib"});
MQDoStored(msg);
}
private void MQPrepared()
{
//MQ 없으면 생성 있으면 해당 큐 객체 반환
if(MessageQueue.Exists(@".\Private$\CJIJAdvertisement02"))
msmq = new System.Messaging.MessageQueue(@".\Private$\CJIJAdvertisement02");
else
msmq = MessageQueue.Create(@".\Private$\CJIJAdvertisement02");
}
private int MQDoStored(Message objMsg)
{
int returnValue, AdvertisementCD, nGender, nAge;
//MQ 메세지 받아서 데이터로 저장하는 곳
string strLabel = objMsg.Label.ToString();
string strBody = (string)objMsg.Body.ToString();
string [] vData = strBody.Split(new Char [] {'_'});
AdvertisementCD = Convert.ToInt16(vData[0].ToString());
nGender = Convert.ToInt16(vData[1].ToString());
nAge = Convert.ToInt16(vData[2].ToString());
returnValue = AdverStat_Log(strLabel, AdvertisementCD, nGender, nAge);
//returnValue = BOobj.AdverStat_Log(strLabel, AdvertisementCD, nGender, nAge);
if(returnValue == -1)
{
Err_EventLogWrite("MQDoStore Failed / Label : " + strLabel + " / Body : " + AdvertisementCD.ToString() + "_" + nGender.ToString() + "_" + nAge.ToString());
}
return returnValue;
}
public static int AdverStat_Log(string procName, int AdvertisementCD, int nGender, int nAge)
{
//MQ 메세지 받아서 데이터로 저장하는 곳
int returnValue = 0;
int effectrow = 0;
string connAdvertisement_Action;
connAdvertisement_Action = "Network Library=DBMSSOCN; Data Source=210.174.197.112; User ID=webaccount; Password=&dnpqdblog%^&; Initial Catalog=Advertisement_Action";
DbObject obj = new DbObject(connAdvertisement_Action);
switch(procName.ToLower())
{
case "impression":
procName="up_Adsmanager_Impression_Action_set";
break;
case "click":
procName="up_Adsmanager_Click_Action_set";
break;
default:
procName="up_Adsmanager_Impression_Action_set";
break;
}
SqlParameter[] parameters = {
new SqlParameter("@AdvertisementCD", SqlDbType.Int, 4),
new SqlParameter("@nGender", SqlDbType.TinyInt, 2),
new SqlParameter("@nAge", SqlDbType.SmallInt, 4)
};
parameters[0].Value = AdvertisementCD;
parameters[1].Value = nGender;
parameters[2].Value = nAge;
try
{
returnValue = obj.RunProcedure(procName, parameters, out effectrow);
return returnValue;
}
catch(SqlException e)
{
AdverServerWinSvc.Err_EventLogWrite("DbObject Failed / Err Number : " + e.Number+ " / Err Source : " + e.Source + " / Err Message : " + e.Message + " / Err ProcName" + e.Procedure);
return -1;
}
finally
{
obj = null;
}
}
///
/// 사용 중인 모든 리소스를 정리합니다.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
public static void Err_EventLogWrite(Exception e)
{
if (!System.Diagnostics.EventLog.SourceExists("CJIJ_Advertisement"))
{
System.Diagnostics.EventLog.CreateEventSource("CJIJ_Advertisement", "CJIJ_Advertisement_Err");
}
System.Diagnostics.EventLog EventLog1 = new System.Diagnostics.EventLog();
EventLog1.Source = "CJIJ_Advertisement";
EventLog1.WriteEntry(e.Message);
}
public static void Err_EventLogWrite(string strLogMsg)
{
if (!System.Diagnostics.EventLog.SourceExists("CJIJ_Advertisement"))
{
System.Diagnostics.EventLog.CreateEventSource("CJIJ_Advertisement", "CJIJ_Advertisement_Log");
}
System.Diagnostics.EventLog EventLog1 = new System.Diagnostics.EventLog();
EventLog1.Source = "CJIJ_Advertisement";
EventLog1.WriteEntry(strLogMsg);
}
///
/// 서비스가 작업을 수행할 수 있도록 필요한 동작을 설정합니다.
///
protected override void OnStart(string[] args)
{
Err_EventLogWrite("CJIJ Advertisememt Win Svc Start (email : sorry every one)");
}
protected override void OnContinue()
{
this.timer1.Enabled=true;
InitializeComponent();
}
///
/// 이 서비스를 중지합니다.
///
protected override void OnStop()
{
this.timer1.Enabled=false;
Err_EventLogWrite("CJIJ Advertisememt Win Svc End (email : sorry evenyone~)");
}
}
}
-------------------- DATA BASE Query Global ------------------------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
namespace CJIJ.DataCore
{
///
/// Class1에 대한 요약 설명입니다.
///
public class DbObject
{
protected SqlConnection Connection;
private string connectionString;
public DbObject(string newConnectionString)
{
connectionString = newConnectionString;
Connection = new SqlConnection(connectionString);
}
protected string ConnectionString
{
get{return connectionString;}
}
private SqlCommand BuildIntCommand(string storedProcName, IDataParameter[] parameters)
{
SqlCommand command = BuildQueryCommand(storedProcName, parameters);
command.Parameters.Add(new SqlParameter("ReturnValue", SqlDbType.Int, 4,
ParameterDirection.ReturnValue, false, 0, 0, string.Empty, DataRowVersion.Default, null));
return command;
}
private SqlCommand BuildQueryCommand(string storedProcName, IDataParameter[] parameters)
{
SqlCommand command = new SqlCommand(storedProcName, Connection);
command.CommandType = CommandType.StoredProcedure;
foreach(SqlParameter parameter in parameters)
{
command.Parameters.Add(parameter);
}
return command;
}
public int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected)
{
int result;
Connection.Open();
SqlCommand command = BuildIntCommand(storedProcName, parameters);
rowsAffected = command.ExecuteNonQuery();
result = (int)command.Parameters["ReturnValue"].Value;
Connection.Close();
return result;
}
public SqlDataReader RunProcedure(string storedProcName, IDataParameter[] parameters)
{
SqlDataReader returnReader;
Connection.Open();
SqlCommand command = BuildQueryCommand(storedProcName, parameters);
command.CommandType = CommandType.StoredProcedure;
returnReader = command.ExecuteReader(CommandBehavior.CloseConnection);
return returnReader;
}
public DataSet RunProcedure(string storedProcName, IDataParameter[] parameters, string tableName)
{
DataSet dataset = new DataSet();
Connection.Open();
SqlDataAdapter sqlDa = new SqlDataAdapter();
sqlDa.SelectCommand = BuildQueryCommand(storedProcName, parameters);
sqlDa.Fill(dataset, tableName);
Connection.Close();
return dataset;
}
public void RunProcedure(string storedProcName, IDataParameter[] parameters, DataSet dataset, string tableName)
{
Connection.Open();
SqlDataAdapter sqlDa = new SqlDataAdapter();
sqlDa.Fill(dataset, tableName);
Connection.Close();
}
}
}
Global Assembly Cache 등록 방법
GAC로 검색하시면 한 페이지 정도 Q&A 가 있는데
원하는 답변이 있을 겁니다.
Strong Name Key Create------------------------
sn -k [생성파일명.snk]
생성된 키파일을
[assembly: AssemblyKeyFile(@"유저패스\생성파일명.snk")]
등록은
gacutil /i Test.dll
해제는
gacutil /u Test
( 해제할 때는 파일명이 아니라 어셈블리명으로..)
타입 등록
tlbexp 컴포넌트 파일명.dll
com+ component 완료
base inheritance C#
namespace inheritance
{
///
/// Class1에 대한 요약 설명입니다.
///
public class Class1
{
private string Class1str1 = "클래스1 private 문자1";
protected string Class1str2 = "클래스1 protected 문자2";
public string Class1str3 = "클래스1 protected 문자3";
}
public sealed class Class2
{
private string Class2str1 = "클래스2 private 문자1";
protected string Class2str2 = "클래스2 protected 문자2";
public string Class1str3 = "클래스2 protected 문자3";
}
public abstract class Class3
{
private string Class3str1 = "클래스3 private 문자1";
protected string Class3str2 = "클래스3 protected 문자2";
public string Class1str3 = "클래스3 protected 문자3";
}
///
/// 위 상속될 클래스
/// 아래 상속받을 클래스
///
class Class4 : Class1
{
///
/// 해당 응용 프로그램의 주 진입점입니다.
///
[STAThread]
static void Main(string[] args)
{
Class1 c1 = new Class1();
Console.WriteLine(c1.Class1str3);
Class2 c2 = new Class2();
Console.WriteLine(c2.Class1str3);
//Class3 c3 = new Class3();
//Console.WriteLine(c3.Class1str3);
}
}
}
Search Directory and Fils by Name C#
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace FilePathAndFileName
{
///
/// Form1에 대한 요약 설명입니다.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtFile;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox txtDir;
public string strDir;
public string strFileType;
private System.Windows.Forms.Label lblFileCount;
///
/// 필수 디자이너 변수입니다.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows Form 디자이너 지원에 필요합니다.
//
InitializeComponent();
//
// TODO: InitializeComponent를 호출한 다음 생성자 코드를 추가합니다.
//
}
///
/// 사용 중인 모든 리소스를 정리합니다.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
///
private void InitializeComponent()
{
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.txtFile = new System.Windows.Forms.TextBox();
this.btnSearch = new System.Windows.Forms.Button();
this.btnSave = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.txtDir = new System.Windows.Forms.TextBox();
this.lblFileCount = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(920, 456);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "검색할 폴더를 입력해 주세요";
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnSave,
this.btnSearch,
this.txtFile,
this.label1});
this.groupBox1.Location = new System.Drawing.Point(624, 472);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(288, 40);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "파일 검색";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(16, 17);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(42, 14);
this.label1.TabIndex = 0;
this.label1.Text = "확장자";
//
// txtFile
//
this.txtFile.Location = new System.Drawing.Point(72, 11);
this.txtFile.Name = "txtFile";
this.txtFile.Size = new System.Drawing.Size(65, 21);
this.txtFile.TabIndex = 1;
this.txtFile.Text = "asp";
this.txtFile.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// btnSearch
//
this.btnSearch.Location = new System.Drawing.Point(144, 11);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(65, 24);
this.btnSearch.TabIndex = 2;
this.btnSearch.Text = "검 색";
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// btnSave
//
this.btnSave.Location = new System.Drawing.Point(224, 11);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(49, 24);
this.btnSave.TabIndex = 3;
this.btnSave.Text = "닫 기";
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// groupBox2
//
this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txtDir});
this.groupBox2.Location = new System.Drawing.Point(408, 472);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(200, 40);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "검색할 폴더";
//
// txtDir
//
this.txtDir.Location = new System.Drawing.Point(8, 12);
this.txtDir.Name = "txtDir";
this.txtDir.Size = new System.Drawing.Size(184, 21);
this.txtDir.TabIndex = 0;
this.txtDir.Text = "";
//
// lblFileCount
//
this.lblFileCount.AutoSize = true;
this.lblFileCount.Location = new System.Drawing.Point(280, 488);
this.lblFileCount.Name = "lblFileCount";
this.lblFileCount.Size = new System.Drawing.Size(73, 14);
this.lblFileCount.TabIndex = 3;
this.lblFileCount.Text = "파일개수 : 0";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(920, 525);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.lblFileCount,
this.groupBox2,
this.groupBox1,
this.richTextBox1});
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
/// 해당 응용 프로그램의 주 진입점입니다.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
strDir = this.txtDir.Text;
strFileType = this.txtFile.Text;
if(strDir=="")
{
MessageBox.Show("검색할 폴더를 입력하게~~~!");
return;
}
if(strFileType=="")
{
MessageBox.Show("검색할 파일 확장자를 입력하게....! 훼훼");
return;
}
this.richTextBox1.Text="";
printDoc(strDir);
this.lblFileCount.Text = this.richTextBox1.Lines.Length.ToString();
}
private void printDoc(string LoadPath)
{
DirectoryInfo dir = new DirectoryInfo(LoadPath);
DirectoryInfo[] subDirs = dir.GetDirectories();
FileInfo[] subFiles = dir.GetFiles();
foreach(FileInfo f in subFiles)
{
if(f.LastWriteTime.ToShortDateString()=="2004-11-13")
{
this.richTextBox1.Text += LoadPath + ", " + f.Name + "\n";
}
if(f.CreationTime.ToShortDateString()=="2004-11-13"){
this.richTextBox1.Text += LoadPath + ", " + f.Name + "\n";
}
/*
if(f.Extension=="." + strFileType.ToLower())
{
this.richTextBox1.Text += LoadPath + ", " + f.Name + "\n";
}
*/
}
foreach(DirectoryInfo d in subDirs)
{
printDoc(d.FullName);
}
}
private void btnSave_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
DB Object Global Class C# Important
using System.Data;
using System.Data.SqlClient;
using System.Xml;
//public abstract class DbObject 이와 같이 추상 클래스로 선언하게 되면 이하 다른 클래스가 직접 상속을 받아 사용해야 한다.
namespace VinsLib
{
public class DbObject
{
protected SqlConnection Connection;
private string connectionString;
public DbObject(string newConnectionString)
{
connectionString = newConnectionString;
Connection = new SqlConnection(connectionString);
}
protected string ConnectionString
{
get
{
return connectionString;
}
}
public SqlCommand BuildIntCommand(string storedProcName, SqlParameter[] parameters)
{
SqlCommand command = BuildQueryCommand(storedProcName, parameters);
command.Parameters.Add
(
new SqlParameter
(
"ReturnValue",
SqlDbType.Int,
4,/*Size*/
ParameterDirection.ReturnValue,
false,/*Null 허용여부*/
0,/*정밀도*/
0,/*스케일*/
string.Empty,
DataRowVersion.Default,null
)
);
return command;
}
public SqlCommand BuildQueryCommand(string storedProcName, SqlParameter[] parameters)
{
SqlCommand command = new SqlCommand(storedProcName, Connection);
command.CommandType = CommandType.StoredProcedure;
foreach(SqlParameter parameter in parameters)
{
command.Parameters.Add(parameter);
}
return command;
}
public int RunProcedure(string storedProcName, SqlParameter[] parameters, out int rowsAffected)
{
int result;
Connection.Open();
SqlCommand command = BuildIntCommand(storedProcName, parameters);
rowsAffected = command.ExecuteNonQuery();
result = (int)command.Parameters["ReturnValue"].Value;
Connection.Close();
rowsAffected = result;
return rowsAffected;
}
public SqlDataReader RunProcedure(string storedProcName, SqlParameter[] parameters)
{
SqlDataReader returnReader;
Connection.Open();
SqlCommand command = BuildQueryCommand(storedProcName, parameters);
command.CommandType = CommandType.StoredProcedure;
returnReader = command.ExecuteReader(CommandBehavior.CloseConnection);
return returnReader;
}
public DataSet RunProcedure(string storedProcName, SqlParameter[] parameters, string tableName)
{
DataSet dataset = new DataSet();
Connection.Open();
SqlDataAdapter sqlDa = new SqlDataAdapter();
sqlDa.SelectCommand = BuildQueryCommand(storedProcName, parameters);
sqlDa.Fill(dataset, tableName);
Connection.Close();
return dataset;
}
public void RunProcedure(string storedProcName, SqlParameter[] parameters, DataSet dataset, string tableName)
{
Connection.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter();
sqlDA.SelectCommand = BuildIntCommand(storedProcName, parameters);
sqlDA.Fill(dataset, tableName);
Connection.Close();
}
}
}
DB Object Global Class C# Important
using System.Data;
using System.Data.SqlClient;
using System.Xml;
//public abstract class DbObject 이와 같이 추상 클래스로 선언하게 되면 이하 다른 클래스가 직접 상속을 받아 사용해야 한다.
namespace VinsLib
{
public class DbObject
{
protected SqlConnection Connection;
private string connectionString;
public DbObject(string newConnectionString)
{
connectionString = newConnectionString;
Connection = new SqlConnection(connectionString);
}
protected string ConnectionString
{
get
{
return connectionString;
}
}
public SqlCommand BuildIntCommand(string storedProcName, SqlParameter[] parameters)
{
SqlCommand command = BuildQueryCommand(storedProcName, parameters);
command.Parameters.Add
(
new SqlParameter
(
"ReturnValue",
SqlDbType.Int,
4,/*Size*/
ParameterDirection.ReturnValue,
false,/*Null 허용여부*/
0,/*정밀도*/
0,/*스케일*/
string.Empty,
DataRowVersion.Default,null
)
);
return command;
}
public SqlCommand BuildQueryCommand(string storedProcName, SqlParameter[] parameters)
{
SqlCommand command = new SqlCommand(storedProcName, Connection);
command.CommandType = CommandType.StoredProcedure;
foreach(SqlParameter parameter in parameters)
{
command.Parameters.Add(parameter);
}
return command;
}
public int RunProcedure(string storedProcName, SqlParameter[] parameters, out int rowsAffected)
{
int result;
Connection.Open();
SqlCommand command = BuildIntCommand(storedProcName, parameters);
rowsAffected = command.ExecuteNonQuery();
result = (int)command.Parameters["ReturnValue"].Value;
Connection.Close();
rowsAffected = result;
return rowsAffected;
}
public SqlDataReader RunProcedure(string storedProcName, SqlParameter[] parameters)
{
SqlDataReader returnReader;
Connection.Open();
SqlCommand command = BuildQueryCommand(storedProcName, parameters);
command.CommandType = CommandType.StoredProcedure;
returnReader = command.ExecuteReader(CommandBehavior.CloseConnection);
return returnReader;
}
public DataSet RunProcedure(string storedProcName, SqlParameter[] parameters, string tableName)
{
DataSet dataset = new DataSet();
Connection.Open();
SqlDataAdapter sqlDa = new SqlDataAdapter();
sqlDa.SelectCommand = BuildQueryCommand(storedProcName, parameters);
sqlDa.Fill(dataset, tableName);
Connection.Close();
return dataset;
}
public void RunProcedure(string storedProcName, SqlParameter[] parameters, DataSet dataset, string tableName)
{
Connection.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter();
sqlDA.SelectCommand = BuildIntCommand(storedProcName, parameters);
sqlDA.Fill(dataset, tableName);
Connection.Close();
}
}
}
XSD With XML VB.NET
Imports System.Xml
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports Microsoft.Data.SqlXml
Module Module1
Sub Main()
'테스트 실폐
FillMyDataSet()
End Sub
Sub ShowXmlToInIE(ByVal strPathToInIE As String)
Dim Ie As New SHDocVw.InternetExplorer()
Ie.Navigate(strPathToInIE)
Ie.Visible = True
End Sub
Public Sub FillMyDataSet()
Dim strPathToResults As String = "C:\MyResults.Xml"
Dim strPathToSchema As String = "C:\MySchema.xsd"
Dim strConn, strSQL As String
strConn = "Provider=SQLOLEDB;User ID=sa;Password=gatsol;Initial Catalog=NorthWind;Data Source=211.236.186.207;"
'strSQL = "Select Top 2 CustomerID, CompanyName From Customers For Xml Auto, Elements"
Dim cmd As New SqlXmlCommand(strConn)
cmd.SchemaPath = strPathToSchema
cmd.CommandText = "Orders[CustomerID='GROSR']"
cmd.CommandType = SqlXmlCommandType.XPath
Dim rdr As XmlReader = cmd.ExecuteXmlReader()
Dim xmlDoc As New XmlDocument()
xmlDoc.Load(rdr)
rdr.Close()
xmlDoc.Save(strPathToResults)
ShowXmlToInIE(strPathToResults)
End Sub
End Module
XmlDataDocument - EnforceConstraints, SelectSingleNode, XPathQuery C#
using System.Data;
using System.Xml;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace CSCommand
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DataSet ds = new DataSet();
FillMyDataSet(ds);
DataTable tblOrder = ds.Tables["Orders"];
tblOrder.PrimaryKey = new DataColumn[]{tblOrder.Columns["OrderID"]};
XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
XmlNode nodOrder;
string strXPathQuery;
strXPathQuery = "/NewDataSet/Orders[OrderID = 10268]";
//XPath Query는 DataSet의 내용에서 하위항목을 지정해서 가져 오게 한다.
//--/NewDataSet/Orders[OrderID = 10268]-->여기에서 NewDataSet 은 DataSet의 이름을 지정 하는 것이고 뒤이어 나오는 Orders는 테이블 이름이다.
//OrderID = 10268는 아시다시피 조건문이다.
nodOrder = xmlDataDoc.SelectSingleNode(strXPathQuery);
ds.EnforceConstraints = false;
nodOrder.ChildNodes[1].InnerText = "vins";
ds.EnforceConstraints = true;
DataRow row = tblOrder.Rows.Find(10268);
Console.WriteLine("OrderID = " + row["OrderID"]);
Console.WriteLine("\t변경후 CustomerID = " + row["CustomerID"]);
Console.WriteLine("\t변경전 CustomerID = " + row["CustomerID", DataRowVersion.Original]);
}
static void ShowXmlInIE(string strPathToXml)
{
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
object objEmpty = Type.Missing;
ie.Navigate(strPathToXml, ref objEmpty, ref objEmpty, ref objEmpty, ref objEmpty);
ie.Visible= true;
}
public static void FillMyDataSet(DataSet ds)
{
string strConn, strSQL;
strConn = "Provider=SQLOLEDB;User ID=sa;Password=gatsol;Initial Catalog=NorthWind;Data Source=211.236.186.207;";
OleDbDataAdapter daOrders, daDetails;
strSQL = "Select OrderID, CustomerID, OrderDate from Orders Where CustomerID = 'Grosr'";
daOrders = new OleDbDataAdapter(strSQL, strConn);
strSQL = "Select OrderID, ProductID, Quantity, UnitPrice From [Order Details] Where OrderID in (Select OrderID from Orders Where CustomerID = 'Grosr') ";
daDetails = new OleDbDataAdapter(strSQL, strConn);
daOrders.Fill(ds, "Orders");
daDetails.Fill(ds, "Details");
}
}
}
XmlDataDocument C#
using System.Data;
using System.Xml;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace CSCommand
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DataSet ds = new DataSet();
FillMyDataSet(ds);
System.Xml.XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
XmlNode nodOrder;
string strXPathQuery;
strXPathQuery = "/NewDataSet/Orders[OrderID = 10268]";
//XPath Query는 DataSet의 내용에서 하위항목을 지정해서 가져 오게 한다.
//--/NewDataSet/Orders[OrderID = 10268]-->여기에서 NewDataSet 은 DataSet의 이름을 지정 하는 것이고 뒤이어 나오는 Orders는 테이블 이름이다.
//OrderID = 10268는 아시다시피 조건문이다.
nodOrder = xmlDataDoc.SelectSingleNode(strXPathQuery);
Console.WriteLine("OrderID = " + nodOrder.ChildNodes[0].InnerText);
Console.WriteLine("CustomerID = " + nodOrder.ChildNodes[0].InnerText);
Console.WriteLine("OrderDate = " + nodOrder.ChildNodes[0].InnerText);
Console.WriteLine("Line Items :");
strXPathQuery = "/NewDataSet/Order_x0020_Details[OrderID=10268]";
foreach(XmlNode nodDetail in xmlDataDoc.SelectNodes(strXPathQuery))
{
Console.WriteLine("\tProductID = " + nodDetail.ChildNodes[1].InnerText);
Console.WriteLine("\tQuantity = " + nodDetail.ChildNodes[2].InnerText);
Console.WriteLine("\tUnitPrice = " + nodDetail.ChildNodes[3].InnerText);
}
}
static void ShowXmlInIE(string strPathToXml)
{
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
object objEmpty = Type.Missing;
ie.Navigate(strPathToXml, ref objEmpty, ref objEmpty, ref objEmpty, ref objEmpty);
ie.Visible= true;
}
public static void FillMyDataSet(DataSet ds)
{
string strConn, strSQL;
strConn = "Provider=SQLOLEDB;User ID=sa;Password=gatsol;Initial Catalog=NorthWind;Data Source=211.236.186.207;";
OleDbDataAdapter daOrders, daDetails;
strSQL = "Select OrderID, CustomerID, OrderDate from Orders Where CustomerID = 'Grosr'";
daOrders = new OleDbDataAdapter(strSQL, strConn);
strSQL = "Select OrderID, ProductID, Quantity, UnitPrice From [Order Details] Where OrderID in (Select OrderID from Orders Where CustomerID = 'Grosr') ";
daDetails = new OleDbDataAdapter(strSQL, strConn);
daOrders.Fill(ds, "Orders");
daDetails.Fill(ds, "Details");
}
}
}
SqlXmlAdapter using InternetExplorer C#
using System.Data;
using System.Xml;
using System.Data.OleDb;
using System.Data.SqlClient;
using Microsoft.Data.SqlXml;
namespace CSCommand
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string strPathToResults = "C:\\MyResults.xml";
string strPathToQuery = "C:\\MyTemplateQuery.xml";
string strConn;
strConn = "Provider=SQLOLEDB;User ID=sa;Password=gatsol;Initial Catalog=NorthWind;Data Source=211.236.186.207;";
//string strSQL;
//strSQL = " Select Top 2 CustomerID, CompanyName From Customers For Xml Auto, Elements ";
SqlXmlCommand cmd = new SqlXmlCommand(strConn);
cmd.CommandText = strPathToQuery;
cmd.CommandType = SqlXmlCommandType.TemplateFile;
DataSet ds = new DataSet();
SqlXmlAdapter da = new SqlXmlAdapter(cmd);
da.Fill(ds);
ds.WriteXml(strPathToResults);
ShowXmlInIE(strPathToResults);
}
static void ShowXmlInIE(string strPathToXml)
{
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
object objEmpty = Type.Missing;
ie.Navigate(strPathToXml, ref objEmpty, ref objEmpty, ref objEmpty, ref objEmpty);
ie.Visible= true;
}
}
}
XmlDocument, SqlXmlCommand C#
using System.Data;
using System.Xml;
using System.Data.OleDb;
using System.Data.SqlClient;
using Microsoft.Data.SqlXml;
namespace CSCommand
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
StartPoint();
}
static void ShowXmlInIE(string strPathToXml)
{
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
object objEmpty = Type.Missing;
ie.Navigate(strPathToXml, ref objEmpty, ref objEmpty, ref objEmpty, ref objEmpty);
ie.Visible= true;
}
public static void StartPoint()
{
string strConn, strSQL;
strConn = "Provider=SQLOLEDB;User ID=sa;Password=gatsol;Initial Catalog=NorthWind;Data Source=211.236.186.207;";
strSQL = "Select Top 2 CustomerID, CompanyName From Customers For Xml Auto, Elements";
SqlXmlCommand cmd = new SqlXmlCommand(strConn);
cmd.CommandText = strSQL;
cmd.RootTag = "ROOT";
XmlDocument xmlDoc = new XmlDocument();
XmlReader rdr = cmd.ExecuteXmlReader();
xmlDoc.Load(rdr);
rdr.Close();
string strPathToXml = "C:\\MyData.Xml";
xmlDoc.Save(strPathToXml);
ShowXmlInIE(strPathToXml);
}
}
}
ADO SQL to XML C#
using System.Data;
using System.Xml;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace CSCommand
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DataSet ds = new DataSet();
FillMyDataSet(ds);
DataTable tblOrder = ds.Tables["Orders"];
tblOrder.PrimaryKey = new DataColumn[]{tblOrder.Columns["OrderID"]};
XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
XmlNode nodOrder;
string strXPathQuery;
strXPathQuery = "/NewDataSet/Orders[OrderID = 10268]";
//XPath Query는 DataSet의 내용에서 하위항목을 지정해서 가져 오게 한다.
//--/NewDataSet/Orders[OrderID = 10268]-->여기에서 NewDataSet 은 DataSet의 이름을 지정 하는 것이고 뒤이어 나오는 Orders는 테이블 이름이다.
//OrderID = 10268는 아시다시피 조건문이다.
nodOrder = xmlDataDoc.SelectSingleNode(strXPathQuery);
ds.EnforceConstraints = false;
nodOrder.ChildNodes[1].InnerText = "vins";
ds.EnforceConstraints = true;
DataRow row = tblOrder.Rows.Find(10268);
Console.WriteLine("OrderID = " + row["OrderID"]);
Console.WriteLine("\t변경후 CustomerID = " + row["CustomerID"]);
Console.WriteLine("\t변경전 CustomerID = " + row["CustomerID", DataRowVersion.Original]);
}
static void ShowXmlInIE(string strPathToXml)
{
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
object objEmpty = Type.Missing;
ie.Navigate(strPathToXml, ref objEmpty, ref objEmpty, ref objEmpty, ref objEmpty);
ie.Visible= true;
}
public static void FillMyDataSet(DataSet ds)
{
string strConn, strSQL;
strConn = "Provider=SQLOLEDB;User ID=sa;Password=gatsol;Initial Catalog=NorthWind;Data Source=211.236.186.207;";
OleDbDataAdapter daOrders, daDetails;
strSQL = "Select OrderID, CustomerID, OrderDate from Orders Where CustomerID = 'Grosr'";
daOrders = new OleDbDataAdapter(strSQL, strConn);
strSQL = "Select OrderID, ProductID, Quantity, UnitPrice From [Order Details] Where OrderID in (Select OrderID from Orders Where CustomerID = 'Grosr') ";
daDetails = new OleDbDataAdapter(strSQL, strConn);
daOrders.Fill(ds, "Orders");
daDetails.Fill(ds, "Details");
}
}
}
GET XML C#
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace CSCommand
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DataSet ds = new DataSet();
FillMyDataSet(ds);
Console.WriteLine(ds.GetXml);
}
static void FillMyDataSet(DataSet ds)
{
string strConn, strSQL;
strConn="Provider=SQLOLEDB;User ID=sa;Password=gatsol;Initial Catalog=NorthWind;Data Source=211.236.186.207;";
OleDbDataAdapter daOrders, daDetails;
strSQL="Select OrderID, CustomerID, OrderDate From Orders Where CustomerID='Grosr' ";
daOrders = new OleDbDataAdapter(strSQL, strConn);
strSQL="Select OrderID, ProductID, Quantity, UnitPrice from [Order Details] Where OrderID in (Select OrderID From Orders Where CustomerID='Grosr') ";
daDetails = new OleDbDataAdapter(strSQL, strConn);
daOrders.Fill(ds,"Orders");
daDetails.Fill(ds,"Details");
}
}
}
ReadXml, ExecuteXmlReader C#
using System.Data;
using System.Xml;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace CSCommand
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string strConn, strSQL;
//strConn = "Provider=SQLOLEDB;User ID=sa;Password=gatsol;Initial Catalog=NorthWind;Data Source=211.236.186.207;";
strConn = ";User ID=sa;Password=gatsol;Initial Catalog=NorthWind;Data Source=211.236.186.207;";
//SqlConnection은 위에 주석 처리된 부분에 보이는 Provider를 지정하면 에러가 난다.
//SqlConnection은 기본적으로 MsSql 연결을 지원하기 때문에 Provider는 알수 없는 옵션인 것이다.
strSQL = "Select Top 2 CustomerID, CompanyName From Customers For Xml Auto, Elements";
SqlConnection cn = new SqlConnection(strConn);
cn.Open();
SqlCommand cmd = new SqlCommand(strSQL, cn);
XmlReader xdx= cmd.ExecuteXmlReader();
DataSet ds = new DataSet();
ds.ReadXml(xdx, XmlReadMode.Fragment);
xdx.Close();
cn.Close();
string strPathToXml = "C:\\MyData.xml";
ds.WriteXml(strPathToXml);
ShowXmlInIE(strPathToXml);
}
static void ShowXmlInIE(string strPathToXml)
{
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
object objEmpty = Type.Missing;
ie.Navigate(strPathToXml, ref objEmpty, ref objEmpty, ref objEmpty, ref objEmpty);
ie.Visible= true;
}
}
}
ADO Rows.Find and Primary Key C#
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace DataReader
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string strConn="Provider=SQLOLEDB;User ID=sa;Password=gatsol;Initial Catalog=vins;Data Source=211.236.186.207;";
string PdsBoardSQL =" Select Idx, Pwd, [Name], [Title], Num, MyRef, NewStep, NewLevel, Email, Url, RegDate, File1, File2, File3, pb.FormTypeID, ft.FormTypeName " +
" from PdsBoard as pb inner join FormType as ft on pb.FormTypeID=ft.FormTypeID ";
OleDbDataAdapter da = new OleDbDataAdapter(PdsBoardSQL, strConn);
DataTable tbl = new DataTable();
da.Fill(tbl);
//Find 메서드는PrimaryKey가 있어야만 동작을 할수 있다.
tbl.PrimaryKey = new DataColumn[] {tbl.Columns["idx"], tbl.Columns["FormTypeID"]};
object[] objCriteria = new object[] {1,1}; //idx=1, FormTypeID=1
DataRow row = tbl.Rows.Find(objCriteria);
if(row==null)
Console.WriteLine("행을 찾을수 없습니다");
else
Console.WriteLine("등록자 이름 : " + row["Name"]);
Console.WriteLine("등록자이메일 : " + row["Email"]);
Console.WriteLine("자료 제목 : " + row["Title"]);
Console.WriteLine("자료실 이름 : " + row["FormTypeName"]);
}
}
}
ADO DataColumn C#
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace DataReader
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string strConn="Provider=SQLOLEDB;User ID=sa;Password=gatsol;Initial Catalog=vins;Data Source=211.236.186.207;";
//OleDbConnection Cn = new OleDbConnection(strConn);
string StrSQL =" Select IDX, Pwd, Name From PdsBoard ";
OleDbDataAdapter daPDS = new OleDbDataAdapter(StrSQL, strConn);
DataSet ds = new DataSet();
daPDS.Fill(ds, "PdsBoard");
DataTable tbl = ds.Tables[0];
Console.WriteLine(tbl.TableName + "DataTable의 정보");
foreach(DataColumn col in tbl.Columns)
Console.WriteLine("\t" + col.ColumnName + " - " + col.DataType.ToString());
}
}
}
ADO TableMappings, ColumnMappings C#
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace DataReader
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string strConn="Provider=SQLOLEDB;User ID=sa;Password=gatsol;Initial Catalog=vins;Data Source=211.236.186.207;";
string StrSQL =" Select IDX, Name, Title From PdsBoard; " +
" Select FormTypeID, FormTypeName From FormType ";
OleDbDataAdapter da = new OleDbDataAdapter(StrSQL,strConn);
da.TableMappings.Add("Table", "PdsBoard");
da.TableMappings[0].ColumnMappings.Add("UIDX", "IDX");
da.TableMappings[0].ColumnMappings.Add("UName", "Name");
da.TableMappings[0].ColumnMappings.Add("UEmail", "Email");
}
}
}