0

Hi guys,
Can you please let me know how I can assign the result of a simple SQL query into a string?
Let's say I have a query like:

string cmd = "Select FName From Emp Where EmpID = 20");
OracleCommand oc = new OracleCommand(cmd, oraConnection);

As you can see the above query will return a single cell value as has been restricted by where clause.Now my question is how I can assign the cell value into a string in order to create a condition statement like:

string res = //result of query;
if(res.StartsWith(s)
{ //do something};
else
{ //do something else};

Thanks in advance for you time

Edited by Behseini: n/a

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Mitja Bonca
Featured Replies
  • You have to use a DataReader class to get a value our of database: [CODE] string cmd = "Select FName From Emp Where EmpID = 20"); OracleCommand oc = new OracleCommand(cmd, oraConnection); //open a connection: oraConnection.Open(); OracleDataReader reader = command.ExecuteReader(); string result = null; if(reader.Read()) result = (string)reader[0]; reader.Close(); oraConnection.Close(); … Read More

1

You have to use a DataReader class to get a value our of database:

string cmd = "Select FName From Emp Where EmpID = 20");
OracleCommand oc = new OracleCommand(cmd, oraConnection);
//open a connection:
oraConnection.Open();
OracleDataReader reader = command.ExecuteReader();
string result = null;
if(reader.Read())
     result = (string)reader[0];
reader.Close();
oraConnection.Close();
if(result.StartsWith("s")
{
     //what would you like to do here?
}
else
{
     //and what would you like to do here?
}

You didnt say what exactly would you like to do in if, else blocks.
About what Cell are you talking about?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.