Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Csharp.net
Hello,
please help me in Csharp for calling a method to retrieve a database value using IBM DB2
 
//------------------------------
public void CreateMyDB2DataReader(string mySelectQuery,string myConnectionString)
{
DB2Connection myConnection = new DB2Connection(myConnectionString);
DB2Command myCommand = new DB2Command(mySelectQuery, myConnection);
myCommand.Connection.Open();
DB2DataReader myReader = myCommand.ExecuteScalar();
try
{
while (myReader.Read())
{
Console.WriteLine(myReader.GetString(0));
}
}
finally
{
myReader.Close();
myConnection.Close();
}
}
//--------------------
 
public static void Main(tring[] args)
{
// HOW TO CALL CreateMyDB2DataReader?
// my connection string is: "Database=Mydata;UID=login;PWD=passwd;";
// the query: "select bdate from mytable where item = 'startdate'";

}
//---------------------------------------------

Thank you very much.
Wajim
Posted 30-Oct-12 19:58pm
Edited 30-Oct-12 23:36pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello,
 
Your solution is very simple Smile | :) just use ExecuteScalar(..) method intead of the ExecuteReader(..) method.
 
regards.
Tarik K.
  Permalink  
Comments
Member 9326300 at 31-Oct-12 4:38am
   
Hi,
thanks for reply.
I have replaced ExecuteReader by ExecuteScalar, I know it is better for retrieving 1 single value. But my question is How do I use it in the MAIN method?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,078
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 31 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100