enter code here
我很难将网络方法传递给标签。我也使用sql将信息传递给label.Can你们都帮帮我吗?
这是我的网络方法。
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 :(得分:0)
请确保问题是否已满?在此方法中,您只需调用WebService方法,然后将Set Some Cp变量设置为Label。我无法得到你想说的话。 GetCPname返回String [],更改Label的文本,我们只需将一些字符串分配给.Text属性。