我有一个名为person
的表。
我使用了所有的“连接”详细信息。我能够提取数据,但只能提取一列。如何使用foreach循环来获取所有详细信息,就像使用查询来获取整个细节一样?
一按按钮,应提取整个数据并将其显示在列表框中
代码:
string connectionstring = OracleConnString(textBox4.Text,textBox5.Text,textBox3.Text,textBox1.Text,textBox2.Text);
string sql = "select * from person";
using (OracleConnection conn = new OracleConnection(connectionstring)) // connect to oracle
{
conn.Open(); // open the oracle connection
using (OracleCommand comm = new OracleCommand(sql, conn)) // create the oracle sql command
{
using (OracleDataReader rdr = comm.ExecuteReader()) // execute the oracle sql and start reading it
{
while (rdr.Read()) // loop through each row from oracle
{
// Console.WriteLine(rdr[0]);
// Console.WriteLine(rdr.GetString(0); );
// Console.WriteLine(rdr["column_name"]);
listBox1.Items.Add(rdr.GetString(0));
listBox1.Items.Add(rdr.GetString(1));
listBox1.Items.Add(rdr.GetString(2));
}
rdr.Close(); // close the oracle reader
}
}
conn.Close(); // close the oracle connection
}
}
public string OracleConnString(string host, string port, string servicename, string user, string pass)
{
return String.Format(
"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={0})" +
"(PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})));User Id={3};Password={4};",
host,
port,
servicename,
user,
pass);
}