How To Mssql 关注



Sorry if I sweat but VBscript for me is abstraction :/

1. How i can connect to database which is stored in label project.

2. How i can make sql query which have value from text_box

select * from table1 where (value of object)

select sum (count) from table1 where (value of object) = table1.part AND current date =

Thank's for help

3 评论

Shotaro Ito
评论操作 固定链接

Hi Tomasz,

1. You can access to database field by built-in function Field("Tablename.Fieldname","defaultvalue(optional)")
*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!
Legacy Poster
评论操作 固定链接

Hi thanks for information.

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


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=""]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