2012-07-03 2 views
1

Windows 응용 프로그램입니다. 원래 테이블의 드롭 다운 메뉴에 대한 데이터 집합이 있습니다. 이제 저장 프로 시저를 사용하고 싶습니다. 코드에서 프로세스를 수정하는 방법?테이블에서 저장 프로 시저로 데이터 집합 바인딩 변경

아마도 가장 좋은 방법은 데이터 집합을 삭제하고 새 데이터 집합을 다시 만드는 것입니다. 디자이너 코드에서 할 수 있습니까?

감사합니다.

편집

protected Problem_DE_DataSet(global::System.Runtime.Serialization.SerializationInfo info, global::System.Runtime.Serialization.StreamingContext context) : 
      base(info, context, false) { 
     if ((this.IsBinarySerialized(info, context) == true)) { 
      this.InitVars(false); 
      global::System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler1 = new global::System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged); 
      this.Tables.CollectionChanged += schemaChangedHandler1; 
      this.Relations.CollectionChanged += schemaChangedHandler1; 
      return; 
     } 
     string strSchema = ((string)(info.GetValue("XmlSchema", typeof(string)))); 
     if ((this.DetermineSchemaSerializationMode(info, context) == global::System.Data.SchemaSerializationMode.IncludeSchema)) { 
      global::System.Data.DataSet ds = new global::System.Data.DataSet(); 
      ds.ReadXmlSchema(new global::System.Xml.XmlTextReader(new global::System.IO.StringReader(strSchema))); 
      if ((ds.Tables["Problem_DE"] != null)) { 
       base.Tables.Add(new Problem_DEDataTable(ds.Tables["Problem_DE"])); 
      } 
      this.DataSetName = ds.DataSetName; 
      this.Prefix = ds.Prefix; 
      this.Namespace = ds.Namespace; 
      this.Locale = ds.Locale; 
      this.CaseSensitive = ds.CaseSensitive; 
      this.EnforceConstraints = ds.EnforceConstraints; 
      this.Merge(ds, false, global::System.Data.MissingSchemaAction.Add); 
      this.InitVars(); 
     } 
     else { 
      this.ReadXmlSchema(new global::System.Xml.XmlTextReader(new global::System.IO.StringReader(strSchema))); 
     } 
     this.GetSerializationData(info, context); 
     global::System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new global::System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged); 
     base.Tables.CollectionChanged += schemaChangedHandler; 
     this.Relations.CollectionChanged += schemaChangedHandler; 
    } 
+0

:

당신이 뭔가를해야한다. 나는이 전체 기능을 삭제하고 내 드롭 다운 메뉴를 채울 것입니다 – phadaphunk

+0

당신의 Windows 응용 프로그램에서 제어 무엇입니까? DropDownList 또는 ComboBox? – phadaphunk

+0

대답을 다시 업데이트했습니다 – phadaphunk

답변

0

코드가 쉽습니다. 당신하는 SqlCommand를 의미하는 저장 프로 시저의 이름에 myCommand

  • 변경 myCommand.Text라고합니다.

  • myCommand.CommandTypeCommandType.StoredProcedure으로 변경하십시오. 당신은 당신이 절차는이 라인을 사용하여 저장에있는 각 매개 변수의

:

  • myCommand.Parameters.AddWithCalue("@YourSQLParameter",YourValue)

나는 이러한 유형의 작업에 대한 DataReaders를 사용하여 좋아합니다.

  • SQLDataReader myReader = myCommand.ExecuteReader();

짜잔! StoredProcedure가 실행되었습니다.

자 이제 소트 절차의 결과를 ComboBox에 추가한다고 가정 해 봅시다.

  • while (myReader.Read()) { myComboBox.Items.Add(myReader["ColumnName"].Tostring(); }

기본 예하지만 난 당신이 포인트를 얻을 확신합니다. 더 많은 정보가 필요하다면 언제든지 this tutorial을 읽을 수 있습니다.

업데이트 :

그것은 당신이 거기까지 게시 생성 된 코드와 지저분한 가지고 있지만 접근 방식은 여전히 ​​동일합니다. 내가 아는 바로는 저장 프로 시저를 사용하여 테이블을 읽고 ComboBox 또는 DropDownList를 특정 필드로 채우고 싶을뿐입니다. 이 디자이너를 사용하지 않고 코드 섹션에서 코드를 처음부터 다시 시도해보고 작동 방식을 이해해야합니다.이 디자이너에서 코드를 생성

 //Creates a connection to your DataBase 
     SqlConnection myConnection = new SqlConnection(@"Server=YOURSERVER;Database=YOURDATABASE;User id=YOURID; Password=YOURPASSWORD"); 
     //Opens the connection 
     myConnection.Open(); 
     //Creates a command (Query) 
     SqlCommand myCommand = myConnection.CreateCommand(); 
     //Sets the type of query to Stored Procedure (EXEC ...) 
     myCommand.CommandType = CommandType.StoredProcedure; 
     //The Query is set to stored procedure so (EXEC THE_NAME_OF_YOU_STOREDPROCEDURE) 
     myCommand.CommandText = "THE_NAME_OF_YOUR_STOREDPROCEDURE"; 

     //This will add each parameter to your query (EXEC THE_NAME_OF_YOURSTOREDPROCEDURE @YOURPARAMETER 
     myCommand.Parameters.AddWithValue("@YOURPARAMETER", THE_VALUE_OF_THE_PARAMETER); 
     SqlDataReader myReader = myCommand.ExecuteReader(); 

     //For each records returned the item from the ["YOURCOLUMN"] will be added to the comboBox 
     while(myReader.Read()) 
     { 
      myComboBox.Items.Add(myReader["YOUR_COLUMN_NAME"]); 
     } 
     myReader.Close(); 
     myConnection.Close(); 
+0

내 업데이트 코드를 확인하십시오. –

+0

코드에 대해 다른 질문이 있으면 언제든지 주저하지 마십시오. – phadaphunk

0

저장 프로 시저를 사용하여 그냥 또 다른 다른 테이블을 제공합니다. 데이터 집합 디자이너를 사용하는 경우 새 테이블 어댑터를 만들고 select 문으로 저장 프로 시저를 사용하면됩니다.

질문하는 내용이 아닌 경우 질문을 몇 가지 코드로 업데이트하십시오.

관련 문제