下面的代码,怎么没有把我数据插入到数据库(其中Insert_teacher是在数据库里写好的insert into插入存储过程)
 ................................................
 ................................................
 ..........
            string str = ConfigurationManager.ConnectionStrings["CourseConnectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(str);
            conn.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("select * from teacher", conn);
            da.Fill(ds, "teacher");
            da.InsertCommand = new SqlCommand("Insert_teacher", conn);
            da.InsertCommand.CommandType = CommandType.StoredProcedure;            da.InsertCommand.Parameters.Add(new SqlParameter("@tid", SqlDbType.Char, 10));
            da.InsertCommand.Parameters["@tid"].Value = teacherNumber.Text.Trim();            da.InsertCommand.Parameters.Add(new SqlParameter("@tname", SqlDbType.VarChar, 50));
            da.InsertCommand.Parameters["@tname"].Value = teacherName.Text.Trim();            da.InsertCommand.Parameters.Add(new SqlParameter("@tpwd", SqlDbType.VarChar, 50));
            da.InsertCommand.Parameters["@tpwd"].Value = teacherPwd.Text.Trim();            da.InsertCommand.Parameters.Add(new SqlParameter("@tpost", SqlDbType.Char, 10));
            da.InsertCommand.Parameters["@tpost"].Value = teacherPost.Text.Trim();
            da.Update(ds, "teacher");
            conn.Close();
            Response.Redirect("ManageList.aspx");       ................
       ...............
       

解决方案 »

  1.   

    你的parameters都是为你的存储过程服务的,执行存储过程的command没有运行。没必要用上da.update这句
    da.Update(ds, "teacher"); 这句话的真正含义一定要弄清楚你的DS没有操作,更新什么啊? <-FILL  CONNECTION
    DS----DA------------SQL
    {Ds--->update-------->
     操
     作}流程要搞懂.
      

  2.   

    da.ExecuteNonQuery(); string str = ConfigurationManager.ConnectionStrings["CourseConnectionString"].ConnectionString; 
                SqlConnection conn = new SqlConnection(str); 
                conn.Open(); 
                DataSet ds = new DataSet(); 
                SqlDataAdapter da = new SqlDataAdapter("select * from teacher", conn); 
                da.Fill(ds, "teacher"); 
                da.InsertCommand = new SqlCommand("Insert_teacher", conn); 
                da.InsertCommand.CommandType = CommandType.StoredProcedure; 
                da.InsertCommand.Parameters.Add(new SqlParameter("@tid", SqlDbType.Char, 10)); 
                da.InsertCommand.Parameters["@tid"].Value = teacherNumber.Text.Trim();             da.InsertCommand.Parameters.Add(new SqlParameter("@tname", SqlDbType.VarChar, 50)); 
                da.InsertCommand.Parameters["@tname"].Value = teacherName.Text.Trim();             da.InsertCommand.Parameters.Add(new SqlParameter("@tpwd", SqlDbType.VarChar, 50)); 
                da.InsertCommand.Parameters["@tpwd"].Value = teacherPwd.Text.Trim();             da.InsertCommand.Parameters.Add(new SqlParameter("@tpost", SqlDbType.Char, 10)); 
                da.InsertCommand.Parameters["@tpost"].Value = teacherPost.Text.Trim();             da.ExecuteNonQuery();
                da.Update(ds, "teacher"); 
                conn.Close(); 
                Response.Redirect("ManageList.aspx"); 
      

  3.   

    da.insertcommand.ExecuteNonQuery();