Jump to content

how to show the table of mssql in program


ken0137
 Share

Recommended Posts

sorry,my english is bad, i'm a fresh man, au3

i want to show one of tables, i don't kown how many rows it have,

but i must display all date in the program like the interface of excel

for example the table "sysusers"

my program like this

Posted Image

if i want ti show any table ,how can i do it ,thank you!

post-30720-1200247187_thumb.jpg

Link to comment
Share on other sites

There are many examples for that on the forum. Just use Search engine.

For example look here

; SimpleADOQuery
; Author: Chris Haney
; Most of this stuff is from another author of the AutoIT forum.
; I made it simplified for novice to pro users and added other connection strings.
; Only works in the beta version of autoit at the present time

#include <GUIConstants.au3>

opt("TrayIconDebug", 1)      ;0=no info, 1=debug line info
opt("ExpandEnvStrings", 1)   ;0=don't expand, 1=do expand
opt("ExpandVarStrings", 1)   ;0=don't expand, 1=do expand

Dim $header = ""
Dim $quantity = 0
Dim $dsncount = 1
Dim $button3

; Use ONE of the next two query statements depending on whether or not you are using a text file
Dim $query = "select * from tablename"; for all BUT text connections
;Dim $query = "select * from filename.txt"; for text connections

; Simply un-remark ONE of the connectors below that you will be using
; Not all connectors require the UID and Pwd commands. Try without them first.
;Dim $DSN = "Driver={SQL Server};Server=ServerName;Database=DatabaseName;Uid=UserID;Pwd=Password;"; SQL connector
;Dim $DSN = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=drive:/folder;Extensions=asc,csv,tab,txt;Persist Security Info=False"; TXT file connector
;Dim $DSN = "Driver={Microsoft Access Driver (*.mdb)};Dbq=drive:/filename.mdb;Uid=UserID;Pwd=Password;"; Access file connector
;Dim $DSN = "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=drive:/filename.xls;DefaultDir=drive:/folder;"; Excel file connector
;Dim $DSN = "Driver={Microsoft ODBC for Oracle};Server=TNSnames_ora;Uid=demo;Pwd=demo;"; Oracle connector

$out = getData($DSN)
ToolTip("")
WinSetTitle("TempWindowName", "", $out&" Rows fetched")

While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $button3
         ExitLoop
   EndSelect
WEnd

Func getData($DSN)
; some things are a bit harder to understand in this part
; .Fields("address").Value is the Value of the Field named "address"
; access database would be the same, but you should call out the full table as well
; like .Fields("Tablename.Fieldname").Value
; and EOF is universal for End Of File
   $cmboVal = ""
   $adoCon = ObjCreate ("ADODB.Connection")
   $adoCon.Open ($DSN)
   $adoRs = ObjCreate ("ADODB.Recordset")
   
   $adoSQL = $query
      
   $adoRs.CursorType = 2
   $adoRs.LockType = 3
   $adoRs.Open ($adoSql, $adoCon)
   
   GUICreate("TempWindowName", 420, 250)
   $button3 = GUICtrlCreateButton("OK", 180, 220, 70, 20)
   
   With $adoRs
      
    ; Get information about Fields collection
      For $n = 0 To .Fields.Count - 1
         $header = $header & .Fields ($n).Name & "|"
      Next
      
      $list = GUICtrlCreateListView(StringTrimRight($header, 1), 10, 10, 400, 200, $LVS_REPORT, $LVS_EX_GRIDLINES)
      
      
      If .RecordCount Then
         $count = 0
         While Not .EOF
            $count = $count + 1
            ToolTip("record search #" & $count, 0, 0)
            For $colum = 0 To .Fields.Count - 1
               $cmboVal = $cmboVal & "" & .Fields ($colum).Value & "|"
            Next
            $cmboVal = StringTrimRight($cmboVal, 1) & @CR
            
            GUICtrlCreateListViewItem($cmboVal, $list)
            $cmboVal = ""
            .MoveNext
         WEnd
         
         GUISetState()
         
      EndIf
      
      
   EndWith
   
   $adoCon.Close
   Return $count
EndFunc ;==>getData
Edited by Zedna
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...