C#SqlDataReader的用法

           string sqljn = "select [序号],[品名],[电压等级],[单位],[型号],[规格],[红本价格]  FROM [book].[dbo].[View_wjprice]";
                using (SqlConnection con=new SqlConnection(consqlstr))
                {
                    con.Open();
                    using (SqlCommand cmd=con.CreateCommand())
                    {
                        cmd.CommandText = sqljn;
                        using (SqlDataReader read=cmd.ExecuteReader(CommandBehavior.CloseConnection))
                        {
                            while (read.Read())
                            {
                                count++;
                                 sql = "insert into eazy_electric(channel_id,company_id,g_id,title,grade,unit,barcode,guide,retail_price,add_time)";
                                sql += " values(12,56,'"+read["序号"] +"','"+ read["品名"] + "','"+ read["电压等级"] + "','" + read["单位"] + "','" + read["型号"] + "','" + read["规格"] + "','" + read["红本价格"] + "','"+DateTime.Now.ToString()+"')";
                                DbHelperSQL.ExecuteSql(sql);
                                  sql = "insert into eazy_electric_history(channel_id,company_id,g_id,title,grade,unit,barcode,guide,retail_price,add_time)";
                                sql += " values(12,56,'"+read["序号"] +"','"+ read["品名"] + "','"+ read["电压等级"] + "','" + read["单位"] + "','" + read["型号"] + "','" + read["规格"] + "','" + read["红本价格"] + "','" + DateTime.Now.ToString() + "')";
                                DbHelperSQL.ExecuteSql(sql);
                            }
                        }

                    }
                }
 using (SqlDataReader read = DbHelperSQL.ExecuteReader(sql))
                {
                    while (read.Read())
                    {
                       count++;
                        htmlstr += "<a style='text-decoration:none;'>";   
                        htmlstr += "<li class=''>";
                        htmlstr += "<div class='clrfix'>";
                        htmlstr += "<div class='honor_x'>";
                        htmlstr += "<div class='time'>" + read["ylcode"] + "</div>";
                        htmlstr += "</div>";
                        htmlstr += "<div class='honor_n'>"+read["itemname"] +"</div>";
                        htmlstr += "<div class='honor_p'>" + read["itemcontent"] + "</div>   ";
                        htmlstr += "<div class='honor_n'>" + read["danwei"] + "</div>";
                        htmlstr += "<div class='honor_c'>" + read["price"] + "</div>";
                        htmlstr += "</div>";
                        htmlstr += "</li>";
                        htmlstr += "</a>";
                    }
                }

 

posted @ 2016-11-08 14:14  雅比斯  阅读(20111)  评论(0编辑  收藏  举报