加入wsDataContent.Credentials = System.Net.CredentialCache.DefaultCredentials即正常(*号标出)

Private dsData As DataSet

Private Sub LoadDataSet()

Dim successful As Boolean
successful = True

Dim errorMessage As String
errorMessage = “”

dsData = New DataSet
dsData.DataSetName = “db”

Dim dbConn As New OleDbConnection
With dbConn
.ConnectionString = “PROVIDER=SQLOLEDB;Server=(local);DATABASE=db_name;UID=sa;PWD=;”
End With

Dim dbCmdUser As New OleDbCommand
dbCmdUser.Connection = dbConn
dbCmdUser.CommandText = “SELECT * FROM tb_user”
Dim dbCmdProject As New OleDbCommand
dbCmdProject.Connection = dbConn
dbCmdProject.CommandText = “SELECT * FROM tb_project”
Dim dbCmdJob As New OleDbCommand
dbCmdJob.Connection = dbConn
dbCmdJob.CommandText = “SELECT * FROM tb_job”
Dim dbCmdTopic As New OleDbCommand
dbCmdTopic.Connection = dbConn
dbCmdTopic.CommandText = “SELECT * FROM tb_topic”

Dim dbAdUser As New OleDbDataAdapter
dbAdUser.SelectCommand = dbCmdUser
Dim dbAdProject As New OleDbDataAdapter
dbAdProject.SelectCommand = dbCmdProject
Dim dbAdJob As New OleDbDataAdapter
dbAdJob.SelectCommand = dbCmdJob
Dim dbAdTopic As New OleDbDataAdapter
dbAdTopic.SelectCommand = dbCmdTopic

dbAdUser.Fill(dsData, “User”)
dbAdProject.Fill(dsData, “Project”)
dbAdJob.Fill(dsData, “Job”)
dbAdTopic.Fill(dsData, “Topic”)
Catch ex A* **ception
successful = False
errorMessage = ex.Message.ToString
errorMessage = “Error reading data.”
End Try
Catch ex A* **ception
successful = False
errorMessage = “Error opening data connention.”
End Try

If Not successful Then
Throw New Exception(errorMessage)
End If
End Sub

<WebMethod()> _
Public Function getDataSet() As DataSet
Return dsData
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim wsDataContent As DataContent
wsDataContent = New DataContent
wsDataContent.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim ds As DataSet
ds = wsDataContent.getDataSet()
dgMain.DataSource = ds
dgMain.DataMember = “User”
Catch ex A* **ception
MsgBox(ex.Message, , “出错提示”)
End Try
End Sub

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.