private void btnOK_Click(object sender, System.EventArgs e) //点击确定按钮
{
string[] linarr ={ "UnitCode", "DataSource", "UserName" };
string[] linvalue; string strServiceName = txtSrv.Text.Trim();
string strUserID = txtUID.Text.Trim();
string strPWD = txtPWD.Text.Trim(); QZ02_Geomag.mag_C_dbOperation dboper = new QZ02_Geomag.mag_C_dbOperation(strServiceName, strUserID, strPWD);
if (!dboper.OpenConnect())
{
MessageBox.Show("数据库连接失败!请检查服务器名、用户名、密码是否正确。", "数据库连接错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
} if (dboper.GetNowInstallType == "")
{
MessageBox.Show("安装类型错误!", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
} dboper.CloseConnect();
Form_Main.IsConnect = true; linvalue = new string[3] { "", strServiceName, strUserID };
Public_XML.XMLWrite(linarr, linvalue); //记忆参数
this.Close();
}
/// QZ02_Geomag.mag_C_dbOperation dboper = new QZ02_Geomag.mag_C_dbOperation(strServiceName, strUserID, strPWD);这句代码是啥意思?
if (!dboper.OpenConnect())对应的OpenConnect()如下:
public bool OpenConnect() //打开数据库连接
{
try
{
oraConn = new OracleConnection(strConnectionString);
oraConn.Open();
return true;
}
catch (OracleException)
{
return false;
}
}这段代码是返回了什么,详细解释一下
{
string[] linarr ={ "UnitCode", "DataSource", "UserName" };
string[] linvalue; string strServiceName = txtSrv.Text.Trim();
string strUserID = txtUID.Text.Trim();
string strPWD = txtPWD.Text.Trim(); QZ02_Geomag.mag_C_dbOperation dboper = new QZ02_Geomag.mag_C_dbOperation(strServiceName, strUserID, strPWD);
if (!dboper.OpenConnect())
{
MessageBox.Show("数据库连接失败!请检查服务器名、用户名、密码是否正确。", "数据库连接错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
} if (dboper.GetNowInstallType == "")
{
MessageBox.Show("安装类型错误!", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
} dboper.CloseConnect();
Form_Main.IsConnect = true; linvalue = new string[3] { "", strServiceName, strUserID };
Public_XML.XMLWrite(linarr, linvalue); //记忆参数
this.Close();
}
/// QZ02_Geomag.mag_C_dbOperation dboper = new QZ02_Geomag.mag_C_dbOperation(strServiceName, strUserID, strPWD);这句代码是啥意思?
if (!dboper.OpenConnect())对应的OpenConnect()如下:
public bool OpenConnect() //打开数据库连接
{
try
{
oraConn = new OracleConnection(strConnectionString);
oraConn.Open();
return true;
}
catch (OracleException)
{
return false;
}
}这段代码是返回了什么,详细解释一下
传3个参数创建一个对象,应该是数据库操作类OpenConnect
如果正常打开数据库连接则返回true,否则false。返回用于判断当前数据库连接是否可用
以数据库服务地址 用户名 密码初始化一个连接数据库的操作类
!dboper.OpenConnect()表示是dboper.OpenConnect()对立面(这时是真),if条件成立,便执行if语句内的代码,弹出数据库连接失败的消息
if (!dboper.OpenConnect())
{
MessageBox.Show("数据库连接失败!请检查服务器名、用户名、密码是否正确。", "数据库连接错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
只是你贴出来的代码中没有调用