2012-11-29 24 views
0

enter code here我很難將網絡方法傳遞給標籤。我也使用sql將信息傳遞給標籤。你們都可以幫助我嗎?如何將網絡方法傳遞給標籤

這是我的網絡方法。

public string[] GetCPname(string cpname) 
     { 
      OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\\Temp\\StudentsDatabase.mdb"); 
      conn.Open(); 

      //Get the ID of the selected book. 
      OleDbCommand cmd = new OleDbCommand("SELECT ID FROM Student where Name = @name", conn); 
      cmd.Parameters.AddWithValue("@name", cpname); 
      OleDbDataReader reader = cmd.ExecuteReader(); 
      reader.Read(); 
      int cpNameID = reader.GetInt32(0); 

      //Get all the reviews with the Book_ID selected. 
      cmd = new OleDbCommand("SELECT CPname FROM StudentInformation where ID = @id", conn); 
      cmd.Parameters.AddWithValue("@id", cpNameID); 
      reader = cmd.ExecuteReader(); 

      ArrayList result = new ArrayList(); 

      while (reader.Read()) 
      { 
       result.Add(reader.GetString(0)); 
      } 
      // Disconnect from DB 
      reader.Close(); 
      conn.Close(); 
      // Convert ArrayList to string array and return 
      return result.ToArray(typeof(string)) as string[]; 
     } 



This is my coding to pass to the label. 


protected void retrievecpname(string CP) 
     { 

      StudentsWSRef.StudentsWS ws = new StudentsWSRef.StudentsWS(); 
      string[] x = ws.GetStudentNames(); 
      lblcpName.Text = CP; 

     } 

我得到這個代碼的問題,因爲它仍然沒有將信息傳遞給標籤。

+0

你究竟想要傳遞給標籤?你不能傳遞一個方法。你只能設置你想要的屬性。 – ryadavilli

+0

你在哪裏調用了「retrievecpname」函數?我在你的代碼中找不到它 – babooney

+0

我不理解這段代碼,你如何處理'retrievecpname'中的'x'? – JonH

回答

0

請確定問題是否完整?在這個方法中,retrievecpname只是簡單地調用WebService方法,並將一些Cp變量設置爲Label。我無法得到你想說的話。 GetCPname返回String [],要更改Label的文本,我們只需將一些字符串分配給.Text屬性即可。