잘못된 방식으로 접근했을 수 있습니다. 데이터 액세스 레이어 기술을 사용할 때 데이터를 가져올 수 없습니다. 내가 메인 클래스에서 다음 코드를 사용하는 경우 그것은 작동 :데이터 액세스 레이어 기술 데이터 세트 및 어댑터를 사용할 때 데이터를 검색 할 수 없습니다.
private void button1_Click(object sender, RoutedEventArgs e)
{
myCon.connectionString();
string SomeString = string.Empty;
SomeString = "SELECT * FROM TableA";
SqlCommand cmd = new SqlCommand(SomeString, myCon.Con);
adapter = new SqlDataAdapter(cmd);
ds = new DataSet();
adapter.Fill(ds, "TableA");
txtID.Text = ds.Tables[0].Rows[rno][0].ToString();
txtFirstName.Text = ds.Tables[0].Rows[rno][1].ToString();
txtLastName.Text = ds.Tables[0].Rows[rno][2].ToString();
}
내가 데이터를 검색 할 수 없습니다이고 오류가없는 다른 클래스에서 위의 코드를 삽입합니다.
를 ClassA :
public void Button(string id, string firstname, string lastname)
{
myCon.connectionString();
string SomeString = string.Empty;
SqlConnection cnn = myCon.Con;
cnn.Open();
CmdString = "SELECT * FROM TableA";
SqlCommand cmd = new SqlCommand(CmdString, cnn.Con);
adapter = new SqlDataAdapter(cmd);
ds = new DataSet();
adapter.Fill(ds, "Table");
id = ds.Tables[0].Rows[rno][0].ToString();
firstname = ds.Tables[0].Rows[rno][1].ToString();
lastname = ds.Tables[0].Rows[rno][2].ToString();
}
Main 클래스 : 사전에
public partial class MainWindow : Window
{
ClassA objs = new ClassA();
private void button1_Click(object sender, RoutedEventArgs e)
{
objs.Button(txtID.Text, txtFirstName.Text, txtLastName.Text);
}
감사 누군가가 나를 여기에 도울 수 있다면.
문자열 자체는 매개 변수로 전달하지 않습니다. 또한 명시 적 값 할당 대신 바인딩을 사용하는 것이 좋습니다. – Somedust