XWidgetSoft Forum

XWidget & XLaunchpad , Desktop customization
It is currently 2017年 Nov 17日 15:18

All times are UTC - 8 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 2013年 Jan 2日 03:37 
Offline

Joined: 2013年 Jan 2日 03:33
Posts: 2
How do i connect MS Access or My Sql Database with my widget ?


Top
 Profile  
 
PostPosted: 2013年 Jan 2日 20:37 
Offline
User avatar

Joined: 2012年 May 12日 20:32
Posts: 576
you can try to uses Activex/OLE in script to connect MS Access

_________________
XWidget Software Developer
[XWidget for Android] [Lastest version of XWidget] [Lastest patch of XWidget]
[XDesktop for Android/Windows]


Top
 Profile  
 
PostPosted: 2013年 Jan 6日 06:35 
Offline

Joined: 2013年 Jan 2日 03:33
Posts: 2
Thanks i got it

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Sub button2OnClick(Sender)
Dim strConnection, conn, rs, strSQL
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='D:\MyData\DB\waste.mdb'"
Set conn = CreateObject("ADODB.Connection")
conn.Open(strConnection)
Set rs = CreateObject("ADODB.recordset")
strSQL = "Select * from Items"
rs.Open strSQL,conn
rs.MoveFirst
while not rs.EOF
Print(rs("Item_des"))
rs.MoveNext
WEND
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Top
 Profile  
 
PostPosted: 2013年 Mar 20日 18:55 
Offline

Joined: 2013年 Mar 20日 18:47
Posts: 2
Hi, can u be more especific, please? or please an example
Can make a list from a db, with autoupdate?
gracias


Top
 Profile  
 
PostPosted: 2014年 Jul 3日 01:08 
Offline

Joined: 2013年 Oct 26日 08:17
Posts: 362
after studying more on this, now i learned how to do this;
to clarify the example above:


this is an example of how to connect to a database
you should change some parameters in the code to use it on your own database file,
most important ones are these:
1. [dbfile path]: the database file's path that you want to connect to it
ex: in here it's: 'D:\MyData\DB\waste.mdb'
2. [TableName]: the table name in the your db file
ex: in here it's: "Items"
3. [FieldName]: the Field you want to do something on it
ex: in here it's: "Item_des"



=================
Important Note:
Xwidget uses javascript mode by default

to change between javascript/vbscript:
1. open Xwidget Designer
2. from the left Sidebar (Widget tree view), select [Widget Attributes], [widget Attribute] form will be shown
3. from this form, find [Script Lang] dropdown menu, and select one that you desire (JavaScript/VBScript)
4. now in Script Editor you can write the code in the language you have selected
================



this is a VBScript code:
(use it if you are using your widget in VBScript code, not the JavaScript code)
Code:
Sub button2OnClick(Sender)
  Dim strConnection, conn, rs, strSQL
  strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='D:\MyData\DB\waste.mdb'"
  Set conn = CreateObject("ADODB.Connection")
  conn.Open(strConnection)
  Set rs = CreateObject("ADODB.recordset")
  strSQL = "Select * from Items"
  rs.Open strSQL,conn
  rs.MoveFirst
  while not rs.EOF
     Print(rs("Item_des"))
     rs.MoveNext
  WEND
  rs.Close
  Set rs = Nothing
  conn.Close
  Set conn = Nothing
End Sub


JavaScript version of same code is this:
(use this if you're using your widget in JavaScript mode)
Code:
function button2OnClick(Sender)
{
  var strConnection, conn, rs, strSQL
  strConnection = "Provider= Microsoft.Jet.OLEDB.4.0 ;Data Source='D:\MyData\DB\waste.mdb'"
  conn = new ActiveXObject("ADODB.Connection");
  conn.Open(strConnection)
  rs = new ActiveXObject("ADODB.recordset")
  strSQL = "Select * from Items"
  rs.Open(strSQL,conn)
  rs.MoveFirst()
  while(!rs.EOF)
  {
     Print(rs("Item_des"))
     rs.MoveNext()
  }
  rs.Close()
  rs = null
  conn.Close()
  conn = null
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Powered by phpBB® Forum Software © phpBB Group