我正在尝试填充datagridview,但它没有显示也没有显示任何错误。我使用过应用程序配置文件。我只是vb.net的初学者
这里是我的代码............
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("DBCS").ConnectionString)
Try
Dim cmd As String = "select * from tblemp"
con.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd, con)
Dim ds As DataSet = New DataSet
da.Fill(ds, "tblemp")
dgv.DataSource = ds
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
结束班
----------------------- app config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DBCS"
connectionString="Data Source=USER-PC;Initial Catalog=test;Integrated Security=True"
providerName="system.data.sqlclient"/>
</connectionStrings>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
</configuration>
答案 0 :(得分:0)
我找到了答案..需要提一下datamember for datagridview
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd, con)
Dim ds As DataSet = New DataSet
da.Fill(ds, "tblemp")
con.close
dgv.DataSource = ds
dgv.DataMember = "tblemp"