在 C# 应用程序中显示上次成功的 SSIS 作业的日期
Display Date of last successful SSIS job in C# app
我正在按代码进行更新以包括整个 .aspx 源代码,以便帮助我了解在何处输入代码的人更好地了解。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection maindb = new SqlConnection(My_Connection);
protected void Page_Load(object sender, EventArgs e)
{
String str = "Select Statement";
SqlCommand sc = new SqlCommand(str, maindb);
maindb.Open();
sc.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sc;
DataSet ds = new DataSet();
da.Fill(ds, "FirstName");
GridView1.DataSource = ds;
GridView1.DataBind();
maindb.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
String str = "Different Select Statement";
SqlCommand sc = new SqlCommand(str, maindb);
maindb.Open();
sc.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sc;
DataSet ds = new DataSet();
da.Fill(ds, "FirstName");
GridView1.DataSource = ds;
GridView1.DataBind();
maindb.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
我有一个单步作业,每天 运行 秒,它会在 SQL 中更新几个 table 秒。
凭借我对 C# 的基本了解,我创建了一个应用程序,用于在 gridview 中显示存储在 SQL table 中的数据。我想在应用程序上显示上次成功的工作 运行 日期,有点像 "Data Updated On" 类型的东西。
在其他 Stack Overflow 问题上,我发现此代码在 SQL management studio 中显示一行,其中包含上次成功的作业。
DECLARE @job_id binary(16)
SELECT @job_id = job_id FROM msdb.dbo.sysjobs WHERE (name = N'YourJobName')
SELECT TOP 1
CONVERT(DATETIME, RTRIM(run_date))
+ ((run_time / 10000 * 3600)
+ ((run_time % 10000) / 100 * 60)
+ (run_time % 10000) % 100) / (86399.9964) AS run_datetime
, *
FROM
msdb..sysjobhistory sjh
WHERE
sjh.step_id = 0
AND sjh.run_status = 1
AND sjh.job_id = @job_id
ORDER BY
run_datetime DESC
我的问题是如何在实际应用程序中显示日期?
谢谢。
protected void Page_Load(object sender, EventArgs e)
{
String str = "Select Statement";
//Replace 'YourJobName' with the name of your SQL Job!
string sqlSelect = @"DECLARE @job_id binary(16)
SELECT @job_id = job_id FROM msdb.dbo.sysjobs WHERE (name = N'YourJobName')
SELECT TOP 1
CONVERT(DATETIME, RTRIM(run_date))
+ ((run_time / 10000 * 3600)
+ ((run_time % 10000) / 100 * 60)
+ (run_time % 10000) % 100) / (86399.9964) AS run_datetime
, *
FROM
msdb..sysjobhistory sjh
WHERE
sjh.step_id = 0
AND sjh.run_status = 1
AND sjh.job_id = @job_id
ORDER BY
run_datetime DESC";
using(var connection = new SqlConnection(My_Connection))
{
using (var sc = new SqlCommand(str, connection))
{
sc.ExecuteNonQuery();
using (SqlDataAdapter da = new SqlDataAdapter() { SelectCommand = sc })
{
DataSet ds = new DataSet();
da.Fill(ds, "FirstName");
GridView1.DataSource = ds;
}
GridView1.DataBind();
}
using (var adapter = new SqlDataAdapter(sqlSelect, connection))
{
var table = new DataTable();
adapter.Fill(table);
Label1.Text = Convert.ToString(table.Rows[0][0]);
}
}
}
我正在按代码进行更新以包括整个 .aspx 源代码,以便帮助我了解在何处输入代码的人更好地了解。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection maindb = new SqlConnection(My_Connection);
protected void Page_Load(object sender, EventArgs e)
{
String str = "Select Statement";
SqlCommand sc = new SqlCommand(str, maindb);
maindb.Open();
sc.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sc;
DataSet ds = new DataSet();
da.Fill(ds, "FirstName");
GridView1.DataSource = ds;
GridView1.DataBind();
maindb.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
String str = "Different Select Statement";
SqlCommand sc = new SqlCommand(str, maindb);
maindb.Open();
sc.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sc;
DataSet ds = new DataSet();
da.Fill(ds, "FirstName");
GridView1.DataSource = ds;
GridView1.DataBind();
maindb.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
我有一个单步作业,每天 运行 秒,它会在 SQL 中更新几个 table 秒。
凭借我对 C# 的基本了解,我创建了一个应用程序,用于在 gridview 中显示存储在 SQL table 中的数据。我想在应用程序上显示上次成功的工作 运行 日期,有点像 "Data Updated On" 类型的东西。
在其他 Stack Overflow 问题上,我发现此代码在 SQL management studio 中显示一行,其中包含上次成功的作业。
DECLARE @job_id binary(16)
SELECT @job_id = job_id FROM msdb.dbo.sysjobs WHERE (name = N'YourJobName')
SELECT TOP 1
CONVERT(DATETIME, RTRIM(run_date))
+ ((run_time / 10000 * 3600)
+ ((run_time % 10000) / 100 * 60)
+ (run_time % 10000) % 100) / (86399.9964) AS run_datetime
, *
FROM
msdb..sysjobhistory sjh
WHERE
sjh.step_id = 0
AND sjh.run_status = 1
AND sjh.job_id = @job_id
ORDER BY
run_datetime DESC
我的问题是如何在实际应用程序中显示日期?
谢谢。
protected void Page_Load(object sender, EventArgs e)
{
String str = "Select Statement";
//Replace 'YourJobName' with the name of your SQL Job!
string sqlSelect = @"DECLARE @job_id binary(16)
SELECT @job_id = job_id FROM msdb.dbo.sysjobs WHERE (name = N'YourJobName')
SELECT TOP 1
CONVERT(DATETIME, RTRIM(run_date))
+ ((run_time / 10000 * 3600)
+ ((run_time % 10000) / 100 * 60)
+ (run_time % 10000) % 100) / (86399.9964) AS run_datetime
, *
FROM
msdb..sysjobhistory sjh
WHERE
sjh.step_id = 0
AND sjh.run_status = 1
AND sjh.job_id = @job_id
ORDER BY
run_datetime DESC";
using(var connection = new SqlConnection(My_Connection))
{
using (var sc = new SqlCommand(str, connection))
{
sc.ExecuteNonQuery();
using (SqlDataAdapter da = new SqlDataAdapter() { SelectCommand = sc })
{
DataSet ds = new DataSet();
da.Fill(ds, "FirstName");
GridView1.DataSource = ds;
}
GridView1.DataBind();
}
using (var adapter = new SqlDataAdapter(sqlSelect, connection))
{
var table = new DataTable();
adapter.Fill(table);
Label1.Text = Convert.ToString(table.Rows[0][0]);
}
}
}