Zum Hauptinhalt gehen

Suche

Suche

Lookup Sql Field

Kommentare

6 Kommentare

  • Avatar
    Legacy Poster

    you can connect more than one database to a label document.  You just have to set the relation to the two databases after more than one are added.

    0
  • Avatar
    Legacy Poster

    Hi Slickson, I know, i use your idea in other documents, but the database i need to connect to has no relation so i can combine them. I need a connection via VB scripting.

     

    Any help would be greatly appreciated.

    0
  • Avatar
    Legacy Poster

    This is part of a script that I use - maybe it can help you.

     

    '------QUERY PARAMETERS------------------------------------
    'SQL Server:
    sqlserver = "NameOfYourSQL-Server"
    
    'SQL Database:
    sqldb = "NameOfTheSQL-DB"
    
    'SQL DB Table:
    sqltable = "NameOfTheSQL-Table"
    
    'Search for...:
    searchkey = "YourValue"
    
    '...in this column:
    searchcol = "RelevantColumn"
    '----------------------------------------------------------
    
    conpar = "Provider=SQLOLEDB;Data Source=" & sqlserver & ";Trusted_Connection=Yes;Initial Catalog=" & sqldb & ";"
    sqlcall = "SELECT * FROM " & sqltable & " WHERE " & searchcol & "='" & CStr(searchkey) & "'"
    
    Set conn = CreateObject("ADODB.Connection")
    conn.Open conpar
    Set recs = CreateObject("ADODB.Recordset")
    recs.Open sqlcall, conn, 1, 3
    
    0
  • Avatar
    Legacy Poster
    '------QUERY PARAMETERS------------------------------------
    'SQL Server:
    sqlserver = "MYSERVER"
    
    'SQL Database:
    sqldb = "Database"
    
    'SQL DB Table:
    sqltable = "dbo.Data"
    
    'Search for...:
    searchkey = product
    
    '...in this column:
    searchcol = "Product_Code"
    '----------------------------------------------------------
    
    conpar = "Provider=SQLOLEDB;Data Source=" & sqlserver & ";Trusted_Connection=Yes;Initial Catalog=" & sqldb & ";"
    sqlcall = "SELECT * FROM " & sqltable & " WHERE " & searchcol & "='" & CStr(searchkey) & "'"
    
    Set conn = CreateObject("ADODB.Connection")
    conn.Open conpar
    Set recs = CreateObject("ADODB.Recordset")
    recs.Open sqlcall, conn, 1, 3
    
    

    Hi, thanks for your reply. Mabe you can help me a little further... Okay i can make a database connection, but basically what i need working is the script checks whether named data source "product" excist in the database and displays the contents from column "Pictogram1" in my database onto my label. Then, i need to know what script i need to display on my object to fill that data onto my label.

     

    The code i have now in my bartender document options is at onOpen:

    0
  • Avatar
    Legacy Poster

    The way the SQL query is set up in your current script, only records are loaded from the DB that contain "product" in column "Product_Code". You can use

    recs.Fields("Pictogram1")
    

    to get the value in column "Pictogram1". To display the value in the object where the script is located, simply assign that to "Value":

    Value = recs.Fields("Pictogram1")

    This will get the value from the first found record - so this only really works, if the records are unique.

     

    You can check whether a record is found at all using something like this:

    If recs.EOF or recs.BOF Then
    ...
    

     

    Keep in mind though that this is mostly amateur/noob code that I scratched together from the internet. So don't sue me if it doesn't work  :)

    0
  • Avatar
    Legacy Poster

    Hi KM, sorry im not getting any further, anyway thanks for you help.

    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.