Random 專案總結 -12 定義定時器,繫結事件

Lionever發表於2024-04-20

System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
System.Windows.Forms.Timer timer2 = new System.Windows.Forms.Timer();

SqlConnectionStringBuilder sqlb01 = new SqlConnectionStringBuilder();

sqlb01.DataSource = strdata;

sqlb01.InitialCatalog = "random";
sqlb01.UserID = strsa;
sqlb01.Password = strpwd;
sqlb01.IntegratedSecurity = false;
sqlb01.Pooling = true;
SqlConnection conn01 = new SqlConnection();
conn01.ConnectionString = sqlb01.ConnectionString;

// MessageBox.Show(strdata + "11" + strsa + "12" + strpwd);

try
{
conn01.Open();
if (conn01.State.ToString() == "Open")
{
label3.Text = "資料庫連結成功";

timer2.Start();
timer2.Interval = 100;
timer2.Tick += new EventHandler(callback2);//計時器繫結事件
tz.Visible = true;

conn01.Close();
}

}

catch (SqlException sqlex)
{
MessageBox.Show("資料庫配置錯誤,請重新填寫/n");
label3.Text = "資料庫連結失敗";
tz.Visible = false;
conn01.Close();
}

相關文章