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);
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};
if(res.StartsWith(s)
{ //do something};
else
{ //do something else};
Thanks in advance for you time

VulpesRank #55 · 29.2K reputationPosted Apr 28, 2011, 2:43 PM EDT
Soft CornerRank #1,221 · 1.5K reputationPosted Apr 28, 2011, 8:22 PM EDT
I have another e.g for this :
string queryString = "Select FName From Emp Where EmpID = 20";
string res="";
using (OracleConnection connection = new OracleConnection(connectionString))
{
try
{
OracleCommand command = new OracleCommand(queryString, connection);
connection.Open();
OracleDataReader reader = command.ExecuteReader();
while (reader.Read())
{
res=reader.GetString(0);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
// always call Close when done reading.
reader.Close();
connection.Close();
}
}
Ankit NandekarRank #703 · 3.4K reputationPosted Apr 28, 2011, 9:04 PM EDT
string res=Convert.ToString(oc.ExecuteScalar());
it will work.
Mayur GujrathiRank #666 · 3.6K reputationPosted Apr 28, 2011, 10:09 PM EDT