-1
我得到我正在工作的服務器的IP地址,然後將檢測到的IP傳遞給另一個從表中獲取辦公室代碼的方法包含每個辦公室和它的IP在Oracle數據庫下的列表我的問題與經過 的IP來查詢方法2,請幫助傳遞參數到oracle查詢
方法1
private IPAddress Get_CurrentLocalIPAddress()
{
if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
MessageBox.Show("Unable to detect IP Address","Network Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
return null;
}
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
return host.AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);
}
方法2
public void Find_OfficeCode()
{
string oradb = "User Id=user;Password=pwd;";
string commandStr = @"select DATABASE_NAME from office where UPPER(IP_ADDRESS)=:pOfficeIP";
using (OracleConnection conn = new OracleConnection(oradb))
using (OracleCommand cmd = new OracleCommand(commandStr,conn))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("pOfficeIP", OracleDbType.Varchar2).Value = Get_CurrentLocalIPAddress().ToString();
conn.Open();
IDataReader dr = cmd.ExecuteReader();
label3.Text = dr.GetString(dr.GetOrdinal("DATABASE_NAME")).ToString();
}
}
感謝您的幫助和解釋 – samer