내가 가지고있는 것은 Form1.cs의 [디자인]에 내 콤보 상자입니다. SQL 물건을 조작하기 위해 SQLOperations라고하는 별도의 클래스를 만들었는데 어떻게 콤보 상자에 전달합니까? ?C# winforms 콤보 상자의 항목을 별도의 클래스에서 추가하려면
public static void SQLServerPull()
{
string server = "p";
string database = "IBpiopalog";
string security = "SSPI";
string sql = "select server from dbo.ServerList";
SqlConnection con = new SqlConnection("Data Source=" + server + ";Initial Catalog=" + database + ";Integrated Security=" + security);
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
//this below doesnt work because it can't find the comboBox
comboBox1.Items.Add(dr[0].ToString());
//the rest of the code works fine
}
con.Close();
}
왜 메서드를 사용하여 List 또는 문자열 배열을 반환하지 않았습니까? 그런 다음 콤보 상자를 채 웁니다. – Tester101
내가 할 수있을 것 같긴하지만 실제로 직접 전달할 수있는 방법이 없다. –
물론 데이터 액세스 레이어를 UI 유형에 연결하고 싶습니까? – Oded