Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FlexGrid or DataGrid

Status
Not open for further replies.

tfhwargt3

Programmer
Sep 19, 2006
61
0
0
US
I am trying to do two things. I want to connect to my local SQL Server Express Database and display records from a select statement.

I am trying to figure out if I need a FlexGrid or a DataGrid. All I want to do is display data, I don't really need any interactivity with the data, just displayed to the person who runs the VB Script. Also, am I correc to be using a Module for this task?

Second, for a local connection is this right?

Code:
  Option Explicit

Private Sub ProcessAmazon()
    
    Dim conSQL As ADODB.Connection
  Set conSQL = New ADODB.Connection
  conSQL.ConnectionString = "Provider=SQLNCLI.1;Integrated Security=SSPI;" & _
      "Persist Security Info=False;" & _
      "AttachDBFileName=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf;Data Source=.\sqlexpress"
  conSQL.Open
  conSQL.Execute "SELECT * FROM Sales;"
  Set rstSQL = Nothing
  conSQL.Close
  Set conSQL = Nothing

End Sub

The reason I ask, is when I run the module with this code included nothing happens except a small window that says "Form1" at the top. I would like the grid to show up like I am used to in Access. Sorry to ask so many questions but I am sort of lost here. I would appreciate any guidance.

Thanks.
 
Try
Code:
Private Sub ProcessAmazon()

    Dim conSQL                      As ADODB.Connection
    Dim rstSQL                      As ADODB.Recordset
    Set conSQL = New ADODB.Connection
    conSQL.ConnectionString = "Provider=SQLNCLI.1;Integrated Security=SSPI;" & _
  "Persist Security Info=False;" & _
  "AttachDBFileName=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf;Data Source=.\sqlexpress"
    conSQL.Open

    Set rstSQL = New ADODB.Recordset
    rstSQL.Open "SELECT * FROM Sales;", conSQL, adOpenStatic, adLockReadOnly
    Set DataGrid1.DataSource = rstSQL

End Sub
Where "DataGrid1" is an ADO Datagrid control
 
Thank you Golom,

One question. I have my server in a LAN in my office. The three other computers will eventually be using this Dataproject and Module on their computers, and the connection string will obviously need to change a bit. The question is, can I still use the AttachDBFileName = ... if I make the HD's on my server shared drives on the network? This way if I make it a Y: drive or something, can I just do:

Code:
conSQL.ConnectionString = "Provider=SQLNCLI.1;Integrated Security=SSPI;" & _
  "Persist Security Info=False;" & _
  "AttachDBFileName=[red]Y:[/red]\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf;Data Source=.\sqlexpress"

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top