理解できないような奇妙な問題があります。サーバー上で実行している商用アプリケーション用の Web コンポーネントを作成しました。cbxGramEnabled.Checked
toを変更するTrue
とFalse
、関数が正常に実行され、変更が行われます。ただし、cbxGramEnabled.Checked
関数を離れると、DB は更新されません。
コンポーネントを実行するコードは次のようになります。
private void WriteToSQL( )
{
WriteEnableGram( _pkKey, cbxGramEnabled.Checked);
}
これcbxGramEnabled.Checked
はCheckBox
、Web アプリのカスタム コンポーネントです。
private void WriteEnableGram( int nPKkey, bool bChecked)
{
string szQuery = string.empty;
if (bChecked == true)
szQuery = "UPDATE dbo.CustomKeyAttr SET EnableGram = 1 WHERE pkCustomKeyAttr = " + nPKkey.ToString() + ";";
else
szQuery = "UPDATE dbo.CustomKeyAttr SET EnableGram = 0 WHERE pkCustomKeyAttr = " + nPKkey.ToString() + ";";
try
{
string szConString = @"Data Source=.\sqlexpress;Initial Catalog=MetricDB;User ID=webuser;Password=mypass;";
using (var Conn = new SqlConnection(szConString))
{
Conn.Open();
using (SqlCommand dbQuery = new SqlCommand(szQuery, Conn))
{
dbQuery.ExecuteNonQuery();
}
}
}
catch (SqlException)
{
}
catch (Exception)
{
}
finally
{
cbxEnableGram.Text = szQuery; // at least display what the query is somewhere on the page....
}
}