retrieving data from MS-SQL database to GRID

HI

i have a MS SQL database with below columns and their data types as below, meanwhile in indusoft i configured a GRID and using the same name as for the grid field column, and the type is as below :-

[Column Name] [MSSQL-TYPE] [INDUSOFT GRID-TYPE]

ID -------------------------- INT (primary key)------- NUMERIC
CamID---------------------INT ------------------------- NUMERIC
CamStartTime-----------TIME------------------------TIME
CamStartDate-----------DATE-----------------------DATE
CamEntryNbr------------VARCHAR(50)-----------TEXT
CamExitNbr--------------VARCHAR(50)-----------TEXT
CamStatus---------------BIT (true/false)-----------TEXT
CreateDATE-------------DATE-----------------------DATE

A single row in SQL Database is as below:-

1 209 09:05:19 2020-04-24 16 11 True 2020-06-02

i have configured Database and when i just put the table name in the Data Source setting (image attached) options in indusoft and execute it,
i put the table name as below:

Name: [cameraidtag]

The GRID can retrieved the MS SQL database according to the table name (cameraidtag). so database reading connection all ok.
and the data is loaded into the grid as below:-

1 209 09:05:19 24-04-2020 16 11 True 02-06-2020

my problem when i create a SQL command to select any data using some conditions, im not sure how to syntactically create a SQL query command in indusoft and load the grid accordingly.

for e.g in the Microsoft SQL query function i can execute this query successfully :-

SELECT * FROM [dbo].[aztitechCrowdCam209] WHERE [ID] BETWEEN 8 AND 20, and i get all the rows from 8th until 20th

So i try the same from indusoft scripts

in the DataSource setting Table tab i wrote this:-

Name: [cameraidtag] WHERE [gridcondition]

So when i click a button, in the button script i update the conditions as below:

$gridCondition = "ID BETWEEN 5 AND 20"

i get invalid object error. it doesnt work.

Database: Error: Invalid object name 'aztitechcrowdcam209 WHERE ID BETWEEN 5 AND 20'........... and its long error message,i just paste some here.

So the grid only gets loaded when i put only the table name in the [cameraidtag] without any condition, how to use with conditions??

i even try to used integer tags as below, i preload the tags with 8 and 20 but i get same error:-

$gridCondition = "ID BETWEEN "&$RowIDmin&" And "&$RowIDmax&""

Can anybody help for above, if i can successfully do above first, then i need to do this which is my ultimate aim:-

i should be able to compare two dates and get the data i want in between, in MS SQL query window i can successfully execute this:-

SELECT * FROM [dbo].[aztitechCrowdCam209] WHERE [CamStartDate] BETWEEN '2020-04-25' AND '2020-06-02' and get the results.

but the same as above , when i try executing similar query from indusoft SQL i get the same invalid object error:-

e.g, i used :-

$gridCondition = "CamstartDate BETWEEN '"&$DateFrom&"' AND '"$DateTo"'"

above script syntax is already error, and i not sure how to write it....

and my question for date comparison is , the indusoft tag only have string tag (both above are strings tags), i can get date-from and date-to using a datetimepicker but it returns the date in strings, can i just direct use strings dates for comparison or i need to convert it??

i can pick the dates as below and load it into a strings tags and plan to use in my condition based SQL command:-

$DateFrom =FormatDateTime($XGet("DateTimePicker1_from","Value.date"),0)
$DateTo =FormatDateTime($XGet("DateTimePicker2_to","Value.date"),0)

how to write correct sql command to get the data inbtwn the picked dates??














Parents
  • [quote]
    Posted By G Shearer on 14 Jun 2020 09:14 PM
    Hi.

    You can set the over-riding Indusoft date format within the Indusoft 'Program Settings.ini' file.

    [International]
    Order=DMY

    The default is MDY.

    You can also set this within the project 'Startup Script', for example:

    $SetDateFormat("/", "DMY")

    Hope this is of use.

    Regards,
    Greg Shearer

    [/quote]

    hi i did quick test, if i do the above is the start-up script, it doesn't effect anything,im not sure as maybe something else is blocking it....

    'Procedures available for all Script groups from the Script task can be implemented here.
    $SetDateFormat("-","YMD")

    above no effect....nothing changes

    but i try the same function in my 'screen script' of the 'calendar screen' as below:-

    'This procedure is executed just once when this screen is open.
    Sub Screen_OnOpen()
    $SetDateFormat("-","YMD")

    the results are:-

    the GRID dates now has changed according to above format.

    But still the "strings tag" in textbox which i used to read the date value from the .net date-time-picker is still on default format as e.g: 6/5/2020

    i read the date value from date time picker as below:-

    $DateFromNet =FormatDateTime($XGet("DateTimePicker1_from","Value.date"),0)
    $DateToNet =FormatDateTime($XGet("DateTimePicker2_to","Value.date"),0)

    and as per that the strings tags loaded with date as e.g 6/5/2020 and not following the format i set using SetDateformat, but as mentioned the GRID date is now displaying following the format, and i just tested reading $Date (current pc date) ,and the format is also according to what i set, only the textbox which loaded the date value from the .NET calender is still on its default date.

    anyway i just wonder why does not work if put it in the start up script as u mentioned,anything else i need do before writing into the startup script.....???






Reply
  • [quote]
    Posted By G Shearer on 14 Jun 2020 09:14 PM
    Hi.

    You can set the over-riding Indusoft date format within the Indusoft 'Program Settings.ini' file.

    [International]
    Order=DMY

    The default is MDY.

    You can also set this within the project 'Startup Script', for example:

    $SetDateFormat("/", "DMY")

    Hope this is of use.

    Regards,
    Greg Shearer

    [/quote]

    hi i did quick test, if i do the above is the start-up script, it doesn't effect anything,im not sure as maybe something else is blocking it....

    'Procedures available for all Script groups from the Script task can be implemented here.
    $SetDateFormat("-","YMD")

    above no effect....nothing changes

    but i try the same function in my 'screen script' of the 'calendar screen' as below:-

    'This procedure is executed just once when this screen is open.
    Sub Screen_OnOpen()
    $SetDateFormat("-","YMD")

    the results are:-

    the GRID dates now has changed according to above format.

    But still the "strings tag" in textbox which i used to read the date value from the .net date-time-picker is still on default format as e.g: 6/5/2020

    i read the date value from date time picker as below:-

    $DateFromNet =FormatDateTime($XGet("DateTimePicker1_from","Value.date"),0)
    $DateToNet =FormatDateTime($XGet("DateTimePicker2_to","Value.date"),0)

    and as per that the strings tags loaded with date as e.g 6/5/2020 and not following the format i set using SetDateformat, but as mentioned the GRID date is now displaying following the format, and i just tested reading $Date (current pc date) ,and the format is also according to what i set, only the textbox which loaded the date value from the .NET calender is still on its default date.

    anyway i just wonder why does not work if put it in the start up script as u mentioned,anything else i need do before writing into the startup script.....???






Children
No Data