猿问

SqlConnection提示异常

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sql2005"].ConnectionString);    
SqlDataAdapter adp = new SqlDataAdapter();        adp.SelectCommand.Connection = con;        adp.SelectCommand.CommandType = CommandType.Text;        adp.SelectCommand.CommandText = "SELECT id,name,pwd,class,age FROM member";

 

提示con对象为空


GCT1015
浏览 459回答 1
1回答

Smart猫小萌

改成这样试试  SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sql2005"].ConnectionString);            SqlCommand cmd = con.CreateCommand();            cmd.CommandText = "SELECT id,name,pwd,class,age FROM member";            SqlDataAdapter adp = new SqlDataAdapter(cmd);            DataSet ds = new DataSet();            con.Open();            adp.Fill(ds);            con.Close();
随时随地看视频慕课网APP
我要回答