0

enter code here我很难将 web 方法传递给标签。我也使用 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;

        }

我对这段代码有疑问,因为它仍然没有将信息传递给标签。

4

1 回答 1

0

Please make sure the Question is full or not?? In this method retrievecpname you are simply call the WebService Method, adn Set Some Cp variable to Label. I couldn't get what you are trying to say. GetCPname returns the String[], to change the text of Label we have to just assign some string to .Text property.

于 2012-11-29T11:20:21.037 回答