从Windows服务中的数据库中选择数据 [英] pick the data from database in windows services

查看:66
本文介绍了从Windows服务中的数据库中选择数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Windows服务中的数据库中检索数据并将其转储到另一个表中。

如何解决这个问题..

帮助我..

解决方案

你可以这样做......

  public   partial   class  Service1:ServiceBase 

{

public Service1()

{

InitializeComponent();

}



受保护 覆盖 void OnStart( string [] args)

{

string connstr = 持久安全信息=错误;集成安全性= SSPI; +

初始目录= Northwind; server = localhost;

SqlConnection conn = new SqlConnection(connstr);

string sql = SELECT CompanyName,来自客户的地址;

SqlDataAdapter da = new SqlDataAdapter(sql,conn);

DataSet ds = new DataSet();

da.Fill(ds, Customers);



//

System.Xml.XmlDataDocument doc = new System.Xml.XmlDataDocument(ds);

// xml的东西

}



受保护 覆盖 void OnStop()

{

// < span class =code-comment> TODO:在此处添加代码以执行停止服务所需的任何拆除。

}







有关详细信息,请参阅此内容...

http://social.msdn.microsoft.com/Forums/en-US/winformsapplications/thread/f9dd9b7d-2240- 40af-86ea-33e241451d9f [ ^ ]

I want to retrive the data from the database in windows services and dump it in another table.
how to di this ..
help me..

解决方案

you can do like this...

public partial class Service1 : ServiceBase

    {

        public Service1()

        {

            InitializeComponent();

        } 

 

        protected override void OnStart(string[] args)

        {

            string connstr = "Persist Security Info=False;Integrated Security=SSPI;" +

                "Initial Catalog=Northwind;server=localhost";

            SqlConnection conn = new SqlConnection(connstr);

            string sql = "SELECT CompanyName,Address From Customers";

            SqlDataAdapter da = new SqlDataAdapter(sql, conn);

            DataSet ds = new DataSet();

            da.Fill(ds, "Customers");

 

            //

            System.Xml.XmlDataDocument doc = new System.Xml.XmlDataDocument(ds);

            // your stuff with the xml

        }

 

        protected override void OnStop()

        {

            // TODO: Add code here to perform any tear-down necessary to stop your service.

        }




See this for more info...
http://social.msdn.microsoft.com/Forums/en-US/winformsapplications/thread/f9dd9b7d-2240-40af-86ea-33e241451d9f[^]


这篇关于从Windows服务中的数据库中选择数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆