查看: 1457|回复: 1
|
(急要)关于VB MsnChart Link SQL 失败, 请教怎样解决
[复制链接]
|
|
我正在做着一个功课,
就是把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 ] |
|
|
|
|
|
|
|
发表于 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 ] |
|
|
|
|
|
|
| |
本周最热论坛帖子
|