2014-05-22 1 views
-3

내가 일할 수있는 SqlDataReader 개체를 얻으려고 내 데이터베이스를 조회하려고 오류가 발생,하지만 난이 오류를 얻을 :나는 ASP

ExecuteReader: Connection property has not been initialised.

내가 SqlDataReader = new SqlDataReader(); 로 초기화 시도를하지만 저를 던졌습니다 또 다른 오류.

protected void Button1_Click(object sender, EventArgs e) 
    { 
     SqlConnection con = new SqlConnection(); 
     con.ConnectionString = "Data Source=BETSY\\SQLEXPRESS;Initial Catalog=Sample;Integrated Security=True"; 
     con.Open(); 
     SqlCommand cmd = new SqlCommand("SELECT * FROM ShoppingList2, con"); 
     SqlDataReader reader = cmd.ExecuteReader(); 
     reader.Close(); 
     con.Close(); 
    } 

답변

4

"SELECT * FROM ShoppingList2", con

+0

덕분에 많이,이 그것을 해결! – Jasper

+0

문제가 해결되면이 대답을 수락하십시오. – Jwit

+0

나는 타이머 때문에 couldnt한다. .. 당신은 10 분을 기다려야한다. – Jasper

1

이 시도이어야한다 ", ShoppingList2 * FROM 사기꾼을 선택"

using (SqlConnection con = new SqlConnection("Data Source=BETSY\\SQLEXPRESS;Initial Catalog=Sample;Integrated Security=True")) 
{ 
    con.Open(); 
    using (SqlCommand com = con.CreateCommand()) 
    { 
     // sql setup stuff here 
     using (SqlDataReader reader = com.ExecuteReader()) 
     { 
      // read data here 
     } 
    } 
} 
관련 문제