XWidgetSoft Forum

XWidget & XLaunchpad , Desktop customization
It is currently May 2nd, 2025, 6:00 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: January 2nd, 2013, 3:37 am 
Offline

Joined: January 2nd, 2013, 3:33 am
Posts: 2
How do i connect MS Access or My Sql Database with my widget ?


Top
 Profile  
 
PostPosted: January 2nd, 2013, 8:37 pm 
Offline
User avatar

Joined: May 12th, 2012, 8:32 pm
Posts: 594
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: January 6th, 2013, 6:35 am 
Offline

Joined: January 2nd, 2013, 3:33 am
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: March 20th, 2013, 6:55 pm 
Offline

Joined: March 20th, 2013, 6:47 pm
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: July 3rd, 2014, 1:08 am 
Offline

Joined: October 26th, 2013, 8:17 am
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 38 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:  

Powered by phpBB® Forum Software © phpBB Group