コード例 #1
0
        private void FrmProgramParameterSub_Load(object sender, EventArgs e)
        {
            string tempvar;

            MyModules.applyGridTheme(dGrid);
            dGrid.Columns[0].Width = 50;
            dGrid.Columns[1].Width = 60;

            for (int h = 1; h <= mlevel; h = h + 1)
            {
                dGrid.Rows.Add();
                dGrid[0, dGrid.Rows.Count - 1].Value = h;
                int g = mPercentageStr.IndexOf(",");
                if (g > 0)
                {
                    tempvar = MyModules.GetIt4Me(mPercentageStr, ",");
                    dGrid[1, dGrid.Rows.Count - 1].Value = tempvar;
                    mPercentageStr = MyModules.Mid(mPercentageStr, g + 1, -1);
                }
                else
                {
                    dGrid[1, dGrid.Rows.Count - 1].Value = mPercentageStr;
                }
            }
        }
コード例 #2
0
        private void cmdAttach_Click(object sender, EventArgs e)
        {
            try
            {
                string connectStr = null;
                if (string.IsNullOrEmpty(txtDBName.Text.Trim()))
                {
                    MessageBox.Show("Pls. select the database", MyModules.strApptitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (chkWinAuthen.Checked)
                {
                    connectStr = "workstation id=" + cboServerName.Text + ";packet size=4096;data source=" + cboServerName.Text + ";Integrated Security=True;initial catalog=master";
                }
                else
                {
                    connectStr = "workstation id=" + cboServerName.Text + ";packet size=4096;user id=" + txtUserID.Text + ";pwd=" + txtPassword.Text + ";data source=" + cboServerName.Text + ";persist security info=False;initial catalog=master";
                }

                SqlConnection SqlCn = new SqlConnection(connectStr);
                SqlCn.Open();
                if (txtAttachName.Text.Trim().Length == 0)
                {
                    MessageBox.Show("Pls. choose a valid data file", MyModules.strApptitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                // ERROR: Not supported in C#: OnErrorStatement

                //'Dim myTrans As SqlTransaction
                //'myTrans = SqlCn.BeginTransaction(IsolationLevel.Serializable, "MyTrans")
                SqlCommand myCommand = new SqlCommand("FetchUserAccessByPwd", SqlCn);

                //'myCommand.Transaction = myTrans

                myCommand.CommandText = "EXEC sp_detach_db @dbname = '" + cboavaliableDB.Text + "'";
                myCommand.ExecuteNonQuery();

                // ERROR: Not supported in C#: OnErrorStatement

                myCommand.CommandText = "EXEC sp_attach_db @dbname = N'" + txtAttachName.Text + "',@filename1 = N'" + txtDBName.Text.Trim() + "',@filename2 = N'" + MyModules.Mid((txtDBName.Text.Trim()), 1, Microsoft.VisualBasic.Strings.InStr(txtDBName.Text.Trim(), ".") - 1) + ".ldf" + "'";
                myCommand.ExecuteNonQuery();
                //'myTrans.Commit()

                myCommand.Connection.Close();
                myCommand.Dispose();
                SqlCn.Close();
                SqlCn.Dispose();
                MessageBox.Show("Successfully Attached", MyModules.strApptitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message, MyModules.strApptitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }