08-22-2013 01:34 PM
I have a MS SQL server express database. I got success to use the Data Store to get a table out of my the database in the NAVIGATOR screen.
What I would like to do, is to perform a query from this table and send the result of the query to the Data Portal.
Can someone help me with this?
08-23-2013 10:43 AM
Have you tried running the Advise loop independently of the other?
08-28-2013 06:26 PM - edited 08-28-2013 06:26 PM
Hi labsergio,
See if you can adapt this script to your needs. You'll need to swap out the ADO connection string for the one that works on your data base, and you'll need to change the table and column names also.
OPTION EXPLICIT Dim z, zMax, ADO, RecordSet, Table, ColStr, CondStr, SortStr, ConnectionStr, QueryStr, RowVals, Channels, AsPos ' needs to be set to a valid ADO connection string for ACCDB file ConnectionStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & AutoActPath ConnectionStr = ConnectionStr & "DataMine.accdb;Persist Security Info=False" ' needs to be set to a valid ADO connection string for MDB file ConnectionStr = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & AutoActPath ConnectionStr = ConnectionStr & "DataMine.mdb;Uid=;Pwd=;" ' construct the SQL query to execute Table = "DataTableWrite" ColStr = "*" ' "DatID,Name,Owner" CondStr = " WHERE DatID < 200" SortStr = " ORDER BY Name" QueryStr = "SELECT " & ColStr & " FROM " & Table & CondStr & SortStr MsgBox QueryStr ' Connect to the data base Set ADO = CreateObject("ADODB.Connection") ADO.Open ConnectionStr ' Execute the query and import the resulting data records into a VBScript variable Set RecordSet = ADO.Execute(QueryStr) RowVals = RecordSet.GetRows() ' Send the resulting data records from the query to new channels in the Data Portal Call DataDelAll Call GroupCreate(Table) Call GroupDefaultSet(GroupCount) Channels = Split(ColStr, ",") IF Trim(ColStr) = "*" THEN zMax = RecordSet.Fields.Count-1 ReDim Channels(zMax) FOR z = 0 TO zMax Channels(z) = RecordSet.Fields(z).Name NEXT ' z END IF For z = 0 To UBound(Channels) AsPos = InStr(UCase(Channels(z)), " AS ") IF AsPos > 1 THEN Channels(z) = Trim(Mid(Channels(z), AsPos+1)) Channels(z) = "[" & GroupDefaultGet & "]/" & Channels(z) Next ' z Channels = ArrayToChannels(RowVals, Channels, 1) ' Disconnect from the database and output the query used and any errors ADO.Close
Brad Turpin
DIAdem Product Support Engineer
National Instruments