DBActivateSQL

I have a table that looks like this

Specification of Test assets Item_number...

1111                     0

2222                     1

3333                     1

4444                     1

If I run after the opening of the database.

iTableHandle = DBActivateSQL (iDatabaseHandle, "SELECT * FROM tblTest WHERE active = 1 AND ItemNumber = '5555'");

DBActivateSQL returns a value same 3 if I replaced with 4444 5555.

Should not DBActivateSQL returns an error because it did not find anything?  I want to fail if the user enters the number of wrong or is inactive.

Paul,

I don't think that the function should give an error, it's simply not find anything.  It would give an error if the SQL statement is incorrect or if you were trying to access a column that does not exist, but not if your WHERE clause returns no value.   You need set up your DBBinds, then call DBFetchNext.  You might have a logic in your code to display an error if the first call to DBFetchNext does not return 0 (indicating no record not found) and then allow your user to enter a different number.

Tags: NI Software

Similar Questions

  • CVI sql toolkit

    Hello

    We use the CVI 2012 and the last sql toolkit. We want to find and update the data in a mysql database. But we have the problem that we still get an error message.

    Here's our code:

    // -----------------------------------------------------------------------

    initialisiert das SQL Toolkit
    DBInit (DB_INIT_MULTITHREADED);
    DBInit (DB_INIT_SINGLETHREADED);

    //
    sprintf (String, "DSN = SYSTEM_DATABASE; Server = 127.0.0.1; Basis of data = backup_demo8; UID = root; PWD = admin");

    //
    hdbc = DBConnect (String);

    //
    HMAP = DBBeginMap (hdbc);

    //
    RW = DBMapColumnToInt (hmap, 'speed', iSpeed, & iSpeedState);
    RW = DBMapColumnToChar (hmap, "datetime", 32, cDateTime, & cDateTimeStat, "");

    Activate the map
    HSTMT = DBActivateMap (hmap "plots");

    Find the folder that we want to update
    While ((rw = DBFetchNext (hstmt)) == DB_SUCCESS)
    {
    //
    If (StrICmpWithoutSurrWhiteSpace (cDateTime, ' 05:37 "" ") == 0)
    break;
    }

    //
    iSpeed = 10;

    Insert the record into the database
    RW = DBPutRecord (hstmt);

    //
    RW = DBDeactivateMap (hmap);

    //
    RW = DBDisconnect (hdbc);

    // -----------------------------------------------------------------------

    When we call the cmd DBPutRecord we get the attached error message

    Can someone help us?

    Thanks in advance

    Best regards

    Oliver

    Hello

    I found a solution in the meantime:

    The Board features seem to be the problem. A google search I found a few comments about similar problems.

    Using the SQL functions activate 'normal', it runs.

    Here is my solution:

    // -----------------------------------------------------------------------

    initialisiert das SQL Toolkit
    DBInit (DB_INIT_MULTITHREADED);
    DBInit (DB_INIT_SINGLETHREADED);

    //
    sprintf (String, "DSN = SYSTEM_DATABASE; Server = 127.0.0.1; Basis of data = database_l01; UID = root; PWD = admin");

    //
    hdbc = DBConnect (String);

    //
    HSQL = DBActivateSQL (hdbc, "' SELECT * FROM 'data_l01'" ");

    //
    RW = DBBindColChar (hsql, SQL_TIME, 32, cTime, & cTimeStat, "");
    RW = DBBindColInt (hsql, SQL_SPEED, iSpeed, & iSpeedState);

    Find the folder that we want to update
    While ((rw = DBFetchNext (hsql)) == DB_SUCCESS)
    {
    //
    If (StrICmpWithoutSurrWhiteSpace (cTime, ' 05:34 "" ") == 0)
    break;
    }

    //
    iSpeed = 15;

    Insert the record into the database
    RW = DBPutRecord (hsql);

    //
    RW = DBDeactivateSQL (hsql);

    //
    RW = DBDisconnect (hdbc);

    // -----------------------------------------------------------------------

    Thank you and Bravo to me :-D

    Oliver

  • SQL Toolkit crashing with multiple threads

    Hello everyone and happy new year!

    I was hoping someone might be able to shed some light on this problem. I update an older application to use multiple threads. In fact, the thread that is causing a problem now is created by using an asynchronous timer.

    I use CVI 2010, and I think the SQL Toolbox is version 2.2.

    If I execute a SQL statement from the main thread, there is no problem.

    stat = DBInit (DB_INIT_MULTITHREADED);
    
    hdbc = DBConnect( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=sample.mdb;Mode=ReadWrite|Share Deny None" );
    hstmt = DBActivateSQL( hdbc, "SELECT * FROM SAMPLES" );
    
    DBDeactivateSQL(hstmt);
    DBDisconnect(hdbc);
    

    If I add code to perform the same duties in a reminder of the timer, it causes a stack overflow error.

    .. Start the main thread

    stat = DBInit (DB_INIT_MULTITHREADED);
    
    NewAsyncTimer (5.0, -1, 1, &gfn_quicktest, 0);
    

    .. end of main thread

    .. and then the reminder of the timer

    int CVICALLBACK gfn_quicktest (int reserved, int timerId, int event,  void *callbackData, int eventData1, int eventData2)
    {
      {
        int hdbc = DBConnect( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=params\\sample.mdb;Mode=ReadWrite|Share Deny None" );
        int hstmt = DBActivateSQL( hdbc, "SELECT * FROM SAMPLES" );
    
       DBDeactivateSQL(hstmt);
        DBDisconnect(hdbc);
      }
    
      return 0;
    }
    

    The program crashes with a stack overflow error when the DBActivateSQL statement is called.

    I understand that the Access ODBC driver can not support multithreaded, but I only connect to this base starting from the same thread with these 2 statements only so it should be good?

    Any idea would be appreciated,
    Thank you
    Ed.

    I just tried this using the sample provided with CVI access database. It uses a DSN instead of mdb. It has worked out well. I see that no reason multithreading would be a problem here, if you open and close the connection in the same segment of code. I see that you use params in the asynchronous callback connection string. Where did this come from? Maybe try to use the database and see if it works.

  • DATEVAL

    Having a problem using SQL ToolKIT in CVI.

    DBActivateSQL DateValue('2010/12/21 15:36:58') in CVI, the return value is "21"), while in the MS ACCESS query, I get the full Date ' 2010/12/21 ' which is correct. What command SQL should I use to get the full value of Date in CVI SQL ToolKIT.

    Thank you.

    Correct me if I'm wrong, but it seems you are trying to do to this exact call: DBActivateSQL (hdbc, "DateValue ('2010 / / 12 / / 21 15:36:58 ')"); without using the dates actually stored in the database, is that correct? DateValue is a feature that only works with the Access databases (it seems that you are using). I don't know why it wouldn't work in CVI because this command should only be sent to the database to manage.

    If the dates are actually stored in a table, then is what you want to do something like this:

    HSTMT = DBActivateSQL (hdbc, "SELECT timestamp OF measure");

    DBBindColChar (hstmt, 1, bufLen, buf, & status, "dd/mm/yyyy");

    While (DBFetchNext (hstmt) == 0)

    ....

    DBDeactivateSQL (hstmt);

    If this is not what you want or need to do perhaps a little more information or a copy of your exact code would help us understand something.

  • How can I transfer content from an XML file in a MS SQL database of the stored procedure using LabWindows/CVI SQL Toolkit?

    Hello

    I have a problem to transfer content to an XML file in a MS SQL database through a stored procedure data/fixed. I am able to transfer the content of the file using method...

    HSTMT = DBPrepareSQL (hdbc, EXEC usp_InsertReport " ... ");

    resCode = DBExecutePreparedSQL (hstmt);

    resCode = DBClosePreparedSQL (hstmt);

    ... but in this case, I am not able to read the return value of the stored procedure.

    I tried to follow the example of the stored procedure in the help documentation (DBPrepareSQL), but I miss a xml data type?

    No idea how to solve my problem?

    Cake of KR

    DianaS salvation,

    Thanks for your comments. During this time I found another way which fullfill my needs:

    resCode = DBSetAttributeDefault (hdbc, ATTR_DB_COMMAND_TYPE, DB_COMMAND_TEXT);

    sprintf (sz_SqlStatement, "DECLARE @TESTID INT EXEC @TESTID = usp_InsertReport ' SELECT 'RetVal' %s = @TESTID", sz_Buffer ");
    HSTMT = DBActivateSQL (hdbc, sz_SqlStatement);

    While ((resCode = DBFetchNext (hstmt)) == DB_SUCCESS)

    {

    / * Enter values in the record. */

    resCode = DBGetColInt (hstmt, 1, & s32_TestId);
    }

    resCode = DBDeactivateSQL (hstmt);

    sz_Buffer is the content of the XML file.

    Cake of KR

  • problem of memory sql toolkit

    Hello

    We use CVI 2012 and SQL Toolkit 2.2. Once a minute, we're looking a record for a special SQL database and we update the data in this leaflet. After update, let's close the database. Whenever we do this procedure that we see in the Task Manager which increases the memory needs of our program.

    After a few minutes (20-30) we get an error message memory.

    Anyone know if there is a problem to know or can someone help us?

    Thanks in advance

    Oliver

    Here is a part of the code:

    //
    hdbc = DBConnect (DATABASE_STRING);

    //
    HSQL = DBActivateSQL (hdbc, "' SELECT * FROM 'data_l01'" ");

    //
    RW = DBBindColChar (hsql, SQL_DATE, 32, cDB_Date, & iDB_Date_State, "");
    RW = DBBindColChar (hsql, SQL_TIME, 32, cDB_Time, & iDB_Time_State, "");
    RW = DBBindColInt (hsql, SQL_SPEED, & iDB_Clock, & iDB_Clock_State);

    Flag, ob der entry found wurde loeschen
    iFoundFlag = 0;

    Find the folder that we want to update
    While ((rw = DBFetchNext (hsql)) == DB_SUCCESS)
    {
    //
    If ((StrICmpWithoutSurrWhiteSpace (cDB_Date, cDate) == 0) &)
    (StrICmpWithoutSurrWhiteSpace (cDB_Time, cTime) == 0))
    {
    Flag, ob der entry found wurde set
    iFoundFlag = 1;
    break;
    }
    } / / Ende von find the folder that we want to update

    Daten uebernehmen
    iDB_Clock = Mutec;

    Insert the record into the database
    RW = DBPutRecord (hsql);

    //
    RW = DBDeactivateSQL (hsql);

    //
    RW = DBDisconnect (hdbc);

    Hi Oliver,.

    To read your code, I understand that you open a connection to the database for each update that you want to run.

    Usually I would advice you to open the database connection to the start once this reference until the program is closed instead of open every time.

    This could potentially solve your problem.

    Please let me know if that solves your problem.

    Best regards

    Raphael

  • Problem with a variable in the SQL statement variable

    Hello

    I try the following query.

    HSTMT = DBActivateSQL (hdbc, "UserLevel SELECT FROM ClassUsers WHERE Password =" + string + "");

    At this point, I get this error:

    Operands of + have illegal types "pointer to char" and "pointer to char".

    I tried this:

    HSTMT = DBActivateSQL (hdbc, "UserLevel SELECT FROM ClassUsers WHERE Password =" + & cadena + "");

    HSTMT = DBActivateSQL (hdbc, "UserLevel SELECT FROM ClassUsers WHERE Password = '" + string + "'");

    Still having the same problem.

    It works fine if I do this.

    HSTMT = DBActivateSQL (hdbc, "SELECT UserLevel UserClass WHERE the password =" cadena' "");

    Where "cadena" is treated as a string.

    Any ideas?

    Thank you!

    The Visual Basic method to concatenate strings with the + operator does not work in C. You can use a number of ways to do this - here is just a sample:

    char string [256] = "SELECT UserLevel OF ClassUsers WHERE password = ';"

    HSTMT = DBActivateSQL (hdbc, strcat (string, String));

    JR

  • mySQL and SQL Toolkit 2.0

    Hello

    I use a database mySQL and sql toolkit 2.0 in application of Labwindows CVI.

    I have a problem when the database increases in size. Indeed, when the number of records reached 3 million, the program memory is 1.7 GB. So, it stops on an Out of Memory error.

    The program memory increases when I use the DBActivateMap function, before adding the records.

    For now, I use the following method to add records:

    DBBeginMap

    DBMapColumnToDouble

    DBMapColumnToDouble

    ...

    DBActivateMap

    DBCreateRecord

    DBPutRecord

    Will there be another opportunity to open the table and add records?

    Thank you for your help.

    Benjamin

    Hello

    Have you tried to use sql statement directly to y to insert a data, for this, you can use this function:

    DBActivateSQL

    And for the sql statement you can use:

    Table INSERT [] [(GBA)]
    {VALUES (list_of_value) | requete_select |} DEFAULT VALUES}

    Kind regards

Maybe you are looking for