2016-05-31 2 views
0

Visual Studio 및 C#을 처음 사용했습니다. 나는 오랫동안이 실수에 갇혀 있었다. 데이터베이스에서 ID를 읽고 제출 단추를 클릭하면 해당 이름을 레이블로 반환하려고합니다. 나는이 내 aspx.cs이하나 이상의 필수 매개 변수에 주어진 값이 없습니다.

protected void Button1_Click(object sender, EventArgs e) 
{ 
    if (!isPostBack) 
    { 
     DataTable dt = new DataTable(); 

     OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\xyz\abc\Visual Studio 2010\WebSites\WebSite9\Uac.mdb"); 






     OleDbCommand cmd = new OleDbCommand(" SELECT DoctorName FROM DoctorInfo WHERE [email protected]", con); 


     cmd.CommandType = CommandType.Text; 
     con.Open(); 

     OleDbDataReader dr = cmd.ExecuteReader(); 
     while (dr.Read()) 
     { 
      Label4.Text = (dr["DoctorName"].ToString()); 

     } 
     dr.Close(); 
     cmd.ExecuteNonQuery(); 
     con.Close(); 



    } 
} 


public bool isPostBack { get; set; } 

public OleDbConnection con { get; set; } 

} 당신은 당신의 commandcommandparameter를 전달해야

답변

0

이 기대 코드 -이다

OleDbDataReader dr = cmd.ExecuteReader(); 

라인에 오류를 받고 있어요 a parameter@p 전화하기 전에 ExecuteReader

cmd.Parameters.AddWithValue("@p",1);