Database SQL server query using C++

Database SQL server query using C++

Page 1 of 1

1 Replies - 4498 Views - Last Post: 02 September 2010 - 12:22 PM Rate Topic: -----

#1 ilokp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-March 09

Database SQL server query using C++

Posted 02 September 2010 - 09:23 AM

Hello,

I am trying to query the Database to return me a number which I would use to assign it to a part. I am using C++ Builder 2010 for this compilation. My code should query the DB, get the Current#, do some validation like - Current# should be >= Start# && <=Stop# && always +1 > previously used Current#,
I believe the DB would efficiently work in Real time by not attempting to assign the same Current# to different simultaneously running parts that request for this number at the same time. I strictly want NO duplication!
char* Next_Num(int ID) {
  static dstring OutputString;
  static char* Nextnum;
  
  try{
	sql = "Select * from myNumbers where ID = '" + ID + "'";
	//the below statement is just the logic and not the correct syntax
	if(Current# <= Stop# && Current# >= Start#){
	NextNum = Current#;
	}
  } catch (Exception& E) {
	OutputString = "ERROR," + dstring(E.Message);
  } 
  return NextNum;
}



So basically how do I select the Database's columnName's value to succesfully compile the above code? Any help much appreciated!

The example DB table (nyNumbers) is below:
ID   Start#    Stop#   Current#
XX      1       10       3



Thanks,
ilok

This post has been edited by ilokp: 02 September 2010 - 10:24 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Database SQL server query using C++

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1276
  • View blog
  • Posts: 4,396
  • Joined: 19-February 09

Re: Database SQL server query using C++

Posted 02 September 2010 - 12:22 PM

Hi, what are you using to connect to the database. Are you using Visual components?

Here ID is an integer and would generally need converting to a string.
sql = "Select * from myNumbers where ID = '" + ID + "'";

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1