如何通过ID在特定时间从C#运行SQL存储过程 [英] How to run a SQL stored procedure from C# at a specific time by ID

查看:83
本文介绍了如何通过ID在特定时间从C#运行SQL存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我需要知道如何在特定时间通过C#运行SQL存储过程。有什么帮助吗? ...


这张照片中的
Imgur:互联网上最棒的图片 [ ^ ]



用户将查询选项卡中的查询和执行时间选项卡中的时间我需要程序执行查询按ID在用户将其放入列执行时间的时间



我的代码是,但这执行查询从文本框我需要让它执行id的查询用户将它放在表ExecQuery中的时间



< pre lang =c#> 使用系统;
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;
使用 System.Data.SqlClient;

命名空间 WindowsFormsApplication1
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}

private void Execute_Click( object sender,EventArgs e)
{
SqlConnection sql = new SqlConnection( 数据源= + .Host.Text + ;初始目录= + .Database .Text + ; Integrated Security = false; User ID = + this .HostUser.Text + ; Password = + this .HostPw.Text + ; MultipleActiveResultSets = true;);
尝试
{
sql.Open();

尝试
{
new SqlCommand(< span class =code-keyword> this
.Query.Text,sql).ExecuteNonQuery();
MessageBox.Show( 执行查询。 成功);
}
catch
{
MessageBox.Show( 查询无效。 查询错误< /跨度>);
}

sql.Close();
}
catch
{
MessageBox.Show( 使用sql连接时出错,请尝试使用正确的sql信息。 错误);
}


}
}
}





我尝试了什么:



i尝试执行查询但是通过文本

解决方案

要安排sql,你需要在sql中创建一个作业,或者你可以通过编写一个窗口服务来使用c#,或者你甚至可以编写一个控制台应用程序,然后使用windows任务调度程序来安排它。



有多种选择可供选择。


Guys now I need to know how to run a SQL stored procedure from through C# at a specific time. Any help please? ...

in this photo Imgur: The most awesome images on the Internet[^]

the user will the query in Query Tab and the time in Execute Time Tab i need the program execute the query By ID in the time which the user put it in the Column Execute Time

My codes is but this execute the query From textbox i need to make it execute the query by id which time the user put it in Table ExecQuery

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Execute_Click(object sender, EventArgs e)
        {
            SqlConnection sql = new SqlConnection("Data Source=" + this.Host.Text + ";Initial Catalog=" + this.Database.Text + ";Integrated Security=false; User ID = " + this.HostUser.Text + "; Password = " + this.HostPw.Text + ";MultipleActiveResultSets=true;");
            try
            {
                sql.Open();

                try
                {
                    new SqlCommand(this.Query.Text, sql).ExecuteNonQuery();
                    MessageBox.Show("Query executed.", "Success");
                }
                catch
                {
                    MessageBox.Show("Invalid query.", "Query Error");
                }

                sql.Close();
            }
            catch
            {
                MessageBox.Show("Error with sql connection, try with a correct sql informations.", "Error");
            }

            
        }
    }
}



What I have tried:

i tried to execute the query but by text

解决方案

To schedule sql you need to create a job in sql or you can use c# by writing a window service or you could even write a console app and then use windows task scheduler to schedule it.

Several options to choose from.


这篇关于如何通过ID在特定时间从C#运行SQL存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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