佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1459|回复: 1

(急要)关于VB MsnChart Link SQL 失败, 请教怎样解决

[复制链接]
观星 该用户已被删除
发表于 21-11-2004 10:48 PM | 显示全部楼层 |阅读模式
我正在做着一个功课,
就是把SQL的Table Link 去VB的MsChart里,
但却linking失败,
请问大家,

How to link sql server with VB to display data and generate graph

其实交的时限已到,我必须在23/11/04也就是后天得到大家的帮助。

谢谢。

[ Last edited by 观星 on 21-11-2004 at 10:50 PM ]
回复

使用道具 举报


ADVERTISEMENT

发表于 22-11-2004 11:06 AM | 显示全部楼层
观星 于 21-11-2004 10:48 PM  说 :
我正在做着一个功课,
就是把SQL的Table Link 去VB的MsChart里,
但却linking失败,
请问大家,

How to link sql server with VB to display data and generate graph
...


Create one form1 and paste these code into it and try.
remember select the activeX data control from reference
GOOD LUCKY




Option Explicit
Dim Cnn As New ADODB.Connection
Private Sub Form_Load()
   
    If OpenSQLConnection Then
       ShowDataInChart
    End If
   
End Sub

Private Function OpenSQLConnection() As Boolean
Dim Provider As String
Dim DataSource As String
Dim UserID As String
Dim Password As String
Dim Database As String
Dim AppName As String
Dim strCn As String

On Error GoTo Errhandler

    Provider = "Provider=SQLOLEDB.1;"
    DataSource = "Data Source=(your SQL server name) ;"
    UserID = "uid=sa;" 'your SQL login ID
    Password = "pwd=sa;" 'your SQL login password
    Database = "Initial Catalog=NorthWind;"
    AppName = "Applications=Testing"

   
    'Define the connection string
    strCn = Provider & DataSource & Database & UserID & Password & AppName
   
    'Open MSSQL Connection
    Cnn.Open strCn
    OpenSQLConnection = True
   
Exit Function
Errhandler:
    MsgBox Err.Description
End Function

Private Sub Form_Unload(Cancel As Integer)
    Set Cnn = Nothing
End Sub

Private Sub ShowDataInChart()
Dim rsProducts As New ADODB.Recordset
Dim strQuery As String

On Error GoTo Errhandler
   
   ' Create a query that retrieves only four fields.
   strQuery = "SELECT ProductName, UnitPrice,UnitsInStock, UnitsOnOrder FROM Products WHERE SupplierID = 1"
   ' Open the recordset.
   rsProducts.Open strQuery, Cnn, adOpenKeyset
   ' Set the DataSource to the recordset.
   With MSChart1
      .ShowLegend = True
      Set .DataSource = rsProducts
   End With
   Set rsProducts = Nothing
Exit Sub
Errhandler:
    MsgBox Err.Description
End Sub

[ Last edited by 元显 on 22-11-2004 at 11:08 AM ]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 28-11-2024 06:11 AM , Processed in 0.112109 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表