none
数据处理问题 RRS feed

  • 问题

  • <1>我想将查询的DataSet插入到数据库:

    DataSet GetDataSet()
            {
                DataSet ds = new DataSet();
                using (SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]))
                {
                    cn.Open();
                    using (SqlDataAdapter dr = new SqlDataAdapter("select je,mc from cwgl_jc_gykh",cn))
                    {
                        dr.Fill(ds);
                    }
                }

                return ds;
            }
            protected void btnOK_Click(object sender, EventArgs e)
            {
                DataSet ds = GetDataSet();
                using(SqlConnection cn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]))
                {
                    cn.Open();
                    using(SqlDataAdapter dr=new SqlDataAdapter())
                    {
                        //dr.SelectCommand = new SqlCommand("select * from cwgl_pz_qtywsr", cn);
                        //SqlCommandBuilder scb = new SqlCommandBuilder(dr);
                        //DataSet ds2=new DataSet();
                        //dr.Fill(ds2);
                        dr.InsertCommand = new SqlCommand();
                        dr.InsertCommand.CommandText = "insert into cwgl_pz_qtywsr(je,zy)values(@je,@zy)";
                        dr.InsertCommand.CommandType = CommandType.Text;
                        dr.InsertCommand.Connection = cn;
                        dr.InsertCommand.Parameters.Add(new SqlParameter("@je", SqlDbType.Decimal,9,"je"));
                        dr.InsertCommand.Parameters.Add(new SqlParameter("@zy", SqlDbType.VarChar,50,"zy"));
                        int count=dr.Update(ds);
             
                    }
                }
            }

    可是一条都没插入进入??也没报错??

    <2>

    怎么以最快的方法插入1W条数据到数据库???

     

    谢谢回复!!

    2008年12月16日 13:56

答案

全部回复