DataCommand를 사용하여 단일 값을 반환하는 저장 프로시저를 실행하려면

 

SqlConnection sqlConnection1 = new SqlConnection("Your Connection String");
SqlCommand cmd = new SqlCommand();
Object returnValue;

cmd.CommandText = "StoredProcedureName";
cmd.CommandType = CommandType. StoredProcedure;
cmd.Connection = sqlConnection1;

sqlConnection1.Open();

returnValue = cmd.ExecuteScalar();

sqlConnection1.Close();


 

 

 

            SqlConnection conn=new SqlConnection(strConn);

            SqlCommand cmd=new SqlCommand("usp_거래처상호탐색",conn);

            conn.Open();

 

            cmd.CommandType=CommandType.StoredProcedure;

            //input거래처코드

            cmd.Parameters.Add("@거래처코드",SqlDbType.VarChar,10);

            cmd.Parameters["@거래처코드"].Value=txt거래처코드.Text;

            cmd.Parameters["@거래처코드"].Direction=ParameterDirection.Input;

 

            //out put 상호

            cmd.Parameters.Add("@상호",SqlDbType.VarChar,30);

            cmd.Parameters["@상호"].Direction=ParameterDirection.Output;

 

            //리턴값

            SqlParameter param=cmd.Parameters.Add("@리턴값",SqlDbType.Int);

            param.Direction=ParameterDirection.ReturnValue;

 

            cmd.ExecuteNonQuery();

            textBox1.Text=cmd.Parameters["@상호"].Value.ToString();

            textBox2.Text=cmd.Parameters["@리턴값"].Value.ToString();

http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=KO-KR&k=k(%22SYSTEM.DIAGNOSTICS.STOPWATCH.%23CTOR%22);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true

반환된 Stopwatch 인스턴스는 중지되고 인스턴스의 경과 시간 속성은 0입니다.

Start 메서드를 사용하면 새 Stopwatch 인스턴스를 통해 경과 시간 측정을 시작할 수 있습니다.StartNew 메서드를 사용하면 새 Stopwatch 인스턴스를 초기화하고 즉시 시작할 수 있습니다.

 

using System;
using System.Diagnostics;
using System.Threading;
class Program
{
    static void Main(string[] args)
    {
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();
        Thread.Sleep(10000);
        stopWatch.Stop();
        // Get the elapsed time as a TimeSpan value.
        TimeSpan ts = stopWatch.Elapsed;

        // Format and display the TimeSpan value.
        string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
            ts.Hours, ts.Minutes, ts.Seconds,
            ts.Milliseconds / 10);
        Console.WriteLine(elapsedTime, "RunTime");
    }
}

 

 

끗~

간단하게 Application.ProductName을 검사해서 실행이 안되게 하는 예제입니다.

 

            
Process[] localAll = Process.GetProcesses(); 
SetMsg("이컴퓨터의 프로세스에  " + Application.ProductName + " 실행되고 있는지 검사....", false);

var query = from c in localAll
            where c.ProcessName == Application.ProductName
            select c;
            if (query.Count() > 1)
            {
                MessageBox.Show("이컴퓨터의 프로세스에  " + Application.ProductName + " 실행되고 있습니다. \n-프로그램을 종료합니다.\n-프로그램을 다른계정으로 실행가능성이 있습니다. \n-작업관리자 시작 > 프로세스를 확인해주세요");
                this.Close();
            }

 SetMsg("프로세스  검사완료....", false); //메세지 박스

배포를 안할땐 그냥

reportViewer.LocalReport.ReportPath = System.Windows.Forms.Application.StartupPath.ToString() + @"\Report1.rdlc";

위와 같이 많이 쓴다 하지만 배포를 했을 땐 저렇게 사용이 안된다.

클릭원스 보안땜시 안되는듯????

 

아래와 같이 리소스로 바로 접근하면 사용이 가능하다

reportViewer.LocalReport.ReportEmbeddedResource = "DLL이름.Report1.rdlc";

 

리포트 파일은 빌드 했을때 포함 리소스로  설정

image

전체화면 창 띄우기

public MainWindow()
{
    InitializeComponent(); 

 WindowState = System.Windows.WindowState.Maximized;

}

해상도 구하기 /듀얼 모니터 구분

fullScreenWindow.WindowStartupLocation = WindowStartupLocation.Manual;            
Debug.Assert(System.Windows.Forms.SystemInformation.MonitorCount > 1);                                
System.Drawing.Rectangle workingArea = System.Windows.Forms.Screen.AllScreens[1].WorkingArea; //듀얼모니터구분               
fullScreenWindow.Left = workingArea.Left; 
fullScreenWindow.Top = workingArea.Top;                
fullScreenWindow.Width = workingArea.Width;                
fullScreenWindow.Height = workingArea.Height;                
fullScreenWindow.WindowState = WindowState.Maximized;//전체화면            
fullScreenWindow.WindowStyle = WindowStyle.None; //테두리 없애기               
fullScreenWindow.Topmost = true;                 
fullScreenWindow.Show();
 
class Example
{
    private static int _staticProperty = 41;
    //설정된 프로퍼티
    public static int StaticProperty    
    {
        get
        {
            return _staticProperty;
        }
        set
        {
            _staticProperty = value;
        }
    }

    private int _instanceProperty = 42;
    public int InstanceProperty    
    {
        get
        {
            return _instanceProperty;
        }
        set
        {
            _instanceProperty = value;
        }
    }

  public static void Main()
    {
        Console.WriteLine("Initial value of class-level property: {0}", 
            Example.StaticProperty);

        PropertyInfo piShared = typeof(Example).GetProperty("StaticProperty");
        piShared.SetValue(null, 76, null);

        Console.WriteLine("Final value of class-level property: {0}", 
            Example.StaticProperty);


        Example exam = new Example();

        Console.WriteLine("\nInitial value of instance property: {0}", 
            exam.InstanceProperty);

        PropertyInfo piInstance = 
            typeof(Example).GetProperty("InstanceProperty");
        piInstance.SetValue(exam, 37, null);

        Console.WriteLine("Final value of instance property: {0}", 
            exam.InstanceProperty);


        exam[17] = "String number 17";
        exam[46] = "String number 46";
        exam[9] = "String number 9";

        Console.WriteLine(
            "\nInitial value of indexed instance property(17): '{0}'", 
            exam[17]);

        // By default, the indexer is named Item, and that name must be used
        // to search for the property. In this example, the indexer is given
        // a different name by using the IndexerNameAttribute attribute.
        PropertyInfo piIndexedInstance = 
            typeof(Example).GetProperty("IndexedInstanceProperty");
        piIndexedInstance.SetValue(
            exam, 
            "New value for string number 17", 
            new object[] { (int) 17 });

        Console.WriteLine(
            "Final value of indexed instance property(17): '{0}'", 
            exam[17]);       
    }

    
}

참고 URL

http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=KO-KR&k=k(SYSTEM.REFLECTION.PROPERTYINFO.SETVALUE);k(SETVALUE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true

 

GetSetMethod 메소드도 찾아보자

http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=KO-KR&k=k(SYSTEM.REFLECTION.PROPERTYINFO.GETSETMETHOD);k(GETSETMETHOD);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true

갑자기 VS 2005 가 실행이 안되었따;;;

검색해보니깐 Termial Services 서비스를 작동시키란다

image

 

image

오류는 해결됐따;;; 근데 터미널 서비스랑 무슨 상관인지?????

Termial Services...

클라이언트 장치가 서버에서 실행 중인 가상의 Windows 2000 Professional 데스크톱 세션 및 Windows 기반의 프로그램을 액세스할 수 있도록, 다중 세션 환경을 제공합니다.

 

Application.StartupPath

응용 프로그램을 시작한 실행 파일의 경로(실행 파일 이름 제외)를 가져옵니다.

private void PrintStartupPath() {
    textBox1.Text = "The path for the executable file that " +
       "started the application is: " +
       Application.StartupPath;
 }

 

Application.OpenForms

응용 프로그램에서 소유하는 열려 있는 폼의 컬렉션을 가져옵니다

 

Application..::.CurrentCulture

현재 스레드에 대한 문화권 정보를 가져오거나 설정합니다.

 

Application..::.CompanyName

응용 프로그램과 관련된 회사 이름을 가져옵니다.

 

Application..::.CurrentCulture

현재 스레드에 대한 문화권 정보를 가져오거나 설정합니다.

private void PrintCurrentCulture() {
    textBox1.Text = "The current culture is: " +
       Application.CurrentCulture.EnglishName;
 }

프로그램 개발할떄 배포할때와 로컬에서 작업할때는 어느정도의 코드 차이가 있다

예를들어 배포할때는 로그인이 필요하지만 개발할때 계속 로긴할려면 졸 짜증이다

또는 서버아이피를 변경해야할때도 있다 이럴때 주석으로 막는 삽질안하고 지시문을 사용해서 간편하게 할수 있다.

초간단한 사용방법

위의 코드는 디버그 모드일땐 자동으로 로긴(GetServerLogin(); )호출
하고 배포일땐 로그인을 해야된다.

Solution Configuation 상태에 따라 실행되지 않는 코드는 저렇게 회색으로 처리된다.

 
서버 아이피를 설정할떄도 변하다.

* 대소문자 구분하네요 (DEBUG O Debug X )

컴파일설정 하기

  클릭~

 

Configuration Manager를 통해 Configuration를 변경 해주면된다.

또는 디버깅 버튼옆에 있는 solution Configuation를 선택해서도 가능 

현재 디버그 모드 

배포모드

 

 

참고 URL

C# 전처리기 지시문

#if(C# 참조)

#else(C# 참조)

#elif(C# 참조)

#endif(C# 참조)

#define(C# 참조)

#undef(C# 참조)

#warning(C# 참조)

#error(C# 참조)

#line(C# 참조)

#region(C# 참조)

#endregion(C# 참조)

#pragma(C# 참조)

#pragma warning(C# 참조)

#pragma checksum(C# 참조)

+ Recent posts