ExecuteReader: Connection property has not been initialized.
my coding is
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(); } } } } }
use this and pass connection object :
SqlCommand cmd=new SqlCommand ("insert into time(project,iteration)values('"+this .name1 .SelectedValue +"','"+this .iteration .SelectedValue +"')",conn);
2.1m questions
2.1m answers
60 comments
57.0k users