ExecuteReader : 연결 속성이 초기화되지 않았습니다.ExecuteReader : 연결 속성이 초기화되지 않았습니다.
내 코딩
당신이 당신의 명령 개체와 같은 연결을 할당해야protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=Si-6\\SQLSERVER2005;Initial Catalog=rags;Integrated Security=SSPI");
SqlDataReader rdr = null;
try
{
// 2. Open the connection
conn.Open();
// 3. Pass the connection to a command object
//SqlCommand cmd = new SqlCommand("select * from Customers", conn);
SqlCommand cmd=new SqlCommand ("insert into time(project,iteration)
values('"+this .name1 .SelectedValue +"','"+this .iteration .SelectedValue +"')");
//
// 4. Use the connection
//
// get query results
rdr = cmd.ExecuteReader();
// print the CustomerID of each record
while (rdr.Read())
{
Console.WriteLine(rdr[0]);
}
}
finally
{
// close the reader
if (rdr != null)
{
rdr.Close();
}
// 5. Close the connection
if (conn != null)
{
conn.Close();
}
}
}
}
}
SqlConnection, SqlCommand 및 SqlReader 개체는 관리되지 않는 리소스를 사용하므로 일회용 개체이므로 작업이 완료 될 때 처분하는 것이 좋습니다. 코드를보다 읽기 쉽게하려면 using 지시문을 사용하면됩니다. – Beatles1692
이러한 대답이 맞습니다. 동의해야합니다. 생성 된 연결로 sqlcommand 연결 속성을 초기화해야합니다. – Saleh