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

Recommended Answers

All 3 Replies

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?

Thanks Mitja ,
Best answer , just as always!

Ayntime :)
bye

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.