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
Mayur GujrathiPosted Apr 29, 2011, 2:09 AM
Ankit NandekarPosted Apr 29, 2011, 1:04 AM
string res=Convert.ToString(oc.ExecuteScalar());
it will work.
Soft CornerPosted Apr 29, 2011, 12:22 AM
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();
}
}
VulpesPosted Apr 28, 2011, 6:43 PM