您的位置:首页 > 编程语言 > C#

c#实现在一个表中有一个Url字段,查每条记录是否在一个文件夹下.如在保留此记录,不在将这个记录删除

2007-05-09 22:29 453 查看
 using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Diagnostics;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["cc2"]);
        con.Open();
        string str = "select * from productsNews";
        SqlCommand cmd = new SqlCommand(str, con);
        SqlDataReader reader = cmd.ExecuteReader();
       
        while (reader.Read())
        {
            string ss = Convert.ToString(reader["Url"]);//
            FileInfo yyy=new FileInfo("D://ep1//"+ss);
            if (!yyy.Exists)
            {
                uplink(ss);
            }            
        }
        reader.Close();
       
        con.Close();
     }
 
    public void uplink(string strl)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["cc2"]);
        con.Open();
        string str = "delete from productsNews where  Url='" + strl + "'";
        SqlCommand cmd = new SqlCommand(str, con);
        cmd.ExecuteNonQuery();
        con.Close();
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  url c# string cmd delete object
相关文章推荐