跳到主内容

搜索

搜索

How To Mssql

评论

3 条评论

  • Avatar
    Shotaro Ito
    Hi Tomasz,

    1. You can access to database field by built-in function Field("Tablename.Fieldname","defaultvalue(optional)")
    [code]ReferenceField("PRODUCTS.PRODUCTCODE")
    Value = Field("PRODUCTS.PRODUCTCODE","NODATA")[/code]
    *ReferenceField tells BarTender to use which field to be used in the script, so place ReferenceField at the beginning of script.
    *You can omit Tablename when you have only one table in database connection setup.

    2. You can get value of object through Format.Objects("Object Name").Value. it works like Label object string datasource.
    so SQL will be
    [code]query = "select * from table1 where id='" & Format.Objects("text_box").Value & "'"[/code]
    alternatively you can get Named sub-string's value, by Format.NamedSubStrings("SubstringName").Value
    [code]query = "select * from table1 where id='" & Format.NamedSubStrings("SUBSTRING1").Value & "'"[/code]
    Which is equal to
    [code]query = "select * from table1 where id='" & SUBSTRING1 & "'"[/code]
    Object Name can be seen / modified by Modify Object > General tab.
    Substrings can be named from Modify object > Datasource tab > [Advanced>>] button to show advanced datasource dialog > Share/Name minitab.

    You cannot set value by object name, as Label object string is read-only. to set value to an object from VB Script, you need to name substring and set value through share name.

    Hope that helps!
    0
  • Avatar
    Legacy Poster
    Hi thanks for information.




    Can You give me examle how i can make insert or update on database by VBScript ??




    Thank's

    0
  • Avatar
    Shotaro Ito
    Hi Tomasz,

    BarTender label format's database connection is read-only, so you need to open your own database connection within VB Script.
    You can place some VBScript on Datasource's Event control script, such as "OnPrintEnd","OnNewRecords" event.
    (something like [url="http://seagullscientific.invisionzone.com/index.php?/topic/201-vbscript-to-populate-a-dropdown-list/page__p__474#entry474"]how to populate dropdown list from table[/url].)

    In that way, the Script would not be BarTender specific, so I recommend you to look for any public web resource to update / insert your desired database via VB Script.

    For reference, here's a Microsoft's article to show how to perform data manipulation tasks.

    Hey, Scripting Guy! The Return of the Database Script
    //64.4.11.252/en-us/magazine/2008.04.heyscriptingguy.aspx
    0

请先登录再写评论。