c# - 当我关闭 Visual Studio 时,Application_end 事件不会更新数据库
问题描述
所以这是我的Application_End
C# 代码,用于使用数组中的值更新数据库表:
protected void Application_End(object sender, EventArgs e)
{
string conStr = Session["ConnectionString"].ToString();
string CMDDDStr = "SELECT * FROM Portfolio";
bool continueFlag = true; //use that somehow
if (continueFlag)
{
SqlDataAdapter daa = new SqlDataAdapter(CMDDDStr, conStr);
DataSet dss = new DataSet();
daa.Fill(dss);
for (int i = 0; i < dss.Tables[0].Rows.Count - 4; i++)
{
int[] services = (int[])Application["services"];
int index0 = services[i];
dss.Tables[0].Rows[i][i+4] = index0;
//// Create connected scenario connection
}
SqlCommandBuilder builder = new SqlCommandBuilder(daa);
daa.UpdateCommand = builder.GetUpdateCommand();
daa.Update(dss);
}
}
这是我的数据库表的 SQL:
CREATE TABLE [dbo].[Portfolio] (
[Description] NVARCHAR (MAX) NULL,
[ImageData] VARBINARY (MAX) NULL,
[delete] NVARCHAR (50) NULL,
[id] INT IDENTITY (1, 1) NOT NULL,
[service0] INT NULL,
[service1] INT NULL,
[service2] INT NULL,
[service3] INT NULL,
[service4] INT NULL,
PRIMARY KEY CLUSTERED ([id] ASC)
);
问题是......这没有任何作用。它不会更新数据库 - 有什么想法吗?
(问题出在代码上)
解决方案
string conaaaStr = Session["ConnectionString"].ToString();
string CMDDDStr = "SELECT * FROM Portfolio";
bool continuaeFlag = true; //use that somehow
if (continuaeFlag)
{
SqlDataAdapter daa = new SqlDataAdapter(CMDDDStr, conaaaStr);
DataSet dss = new DataSet();
daa.Fill(dss);
for (int i = 0; i < dss.Tables[0].Columns.Count - 4; i++)
{
int[] services = (int[])Application["services"];
int index0 = services[i];
dss.Tables[0].Rows[0][i + 4] = index0;
//// Create connected scenario connection
}
SqlCommandBuilder builder = new SqlCommandBuilder(daa);
builder.GetUpdateCommand();
daa.Update(dss);
}
推荐阅读
- r - 使用 ggplot 绘制可能是水平或垂直的直线
- kubernetes - Kubernetes Ingress 后端子路径
- node.js - 亚马逊开发人员一直告诉我功能测试中关于未验证请求的错误
- c - 我的 Unix Shell 项目出现异常错误,请赐教
- ios - iOS 13 仅在用户“允许一次”后再次调用 requestAlwaysAuthorization
- python - 如何平滑 Plotly 3d 曲面图?
- numerical-methods - 数值方法 - 检查 Phi(x) 的域
- python-3.x - TfidfVectorizer 背后的数学原理是什么?
- javascript - 简单函数未正确传递变量
- lisp - 在 lisp 编程中返回一个值