[英]Application_end event doesn't update the database when I close visual studio
所以這是我的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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.