0
我有一個按鈕事件,我正在調用一個函數的按鈕。我已經設置了該按鈕的接受按鈕屬性。但它不是單發事件單擊。在winform按鈕需要點擊兩次擊發事件
private void btnConnect_Click(object sender, EventArgs e)
{
try
{
//Function call for validating the textboxes entry
ValidateForm();
if(lblMessage.Text != string.Empty)
{
//Function call for binding the dropdown with all DB names
BindDBDropDown();
//Function call for binding the operation names in dropdown
SetOperationDropDown();
}
else
{
//Else give the error message to user
lblMessage.Text = "Invalid Credentials";
}
}
catch(Exception ex)
{
//All the exceptions are handled and written in the EventLog.
EventLog log = new EventLog("Application");
log.Source = "MFDBAnalyser";
log.WriteEntry(ex.Message);
}
}
public void BindDBDropDown()
{
SqlConnectionStringBuilder objConnectionString = new SqlConnectionStringBuilder();
objConnectionString.DataSource = txtHost.Text;
objConnectionString.UserID = txtUsername.Text;
objConnectionString.Password = txtPassword.Text;
SqlConnection sConnection = new SqlConnection(objConnectionString.ConnectionString);
//If connected then give this message to user
lblMessage.Visible = true;
lblMessage.Text = "You are connected to the SQL Server....";
try
{
//To Open the connection.
sConnection.Open();
//Query to select the list of databases.
string selectDatabaseNames = @"SELECT
NAME
FROM
[MASTER]..[SYSDATABASES]";
//Create the command object
SqlCommand sCommand = new SqlCommand(selectDatabaseNames, sConnection);
//Create the data set
DataSet sDataset = new DataSet("master..sysdatabases");
//Create the dataadapter object
SqlDataAdapter sDataAdapter = new SqlDataAdapter(selectDatabaseNames, sConnection);
sDataAdapter.TableMappings.Add("Table", "master..sysdatabases");
//Fill the dataset
sDataAdapter.Fill(sDataset);
//Bind the database names in combobox
DataViewManager dsv = sDataset.DefaultViewManager;
//Provides the master mapping between the sourcr table and system.data.datatable
cmbDatabases.DataSource = sDataset.Tables["master..sysdatabases"];
cmbDatabases.DisplayMember = "NAME";
cmbDatabases.ValueMember = ("NAME");
}
catch(Exception ex)
{
//All the exceptions are handled and written in the EventLog.
EventLog logException = new EventLog("Application");
logException.Source = "MFDBAnalyser";
logException.WriteEntry(ex.Message);
MessageBox.Show ("Login Failed!!", "Error Occured");
}
finally
{
//If connection is not closed then close the connection
if(sConnection.State != ConnectionState.Closed)
{
sConnection.Close();
}
}
}
有人能幫我嗎?
你在哪裏註冊事件處理程序?你可以發佈該代碼嗎? – Oded 2010-12-03 10:56:11