本文介绍了记录未显示在datagridview1中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试使用 sql server 在 Datagridview1 中显示记录但是记录不显示 in Datagridview1 并且代码中没有错误。 我希望你能解决这个问题。 问候 Mahmood 我尝试过: 公共 Class Form6 Dim da As 对象 公开 属性 ServerName()作为 字符串 公开 属性 DatabaseName()作为 String 公共 属性登录()作为 字符串 公共 属性密码() As String Private 功能 SqlConn(可选 ByVal 超时作为 整数 = 0 )作为 字符串 ' 初始化 基础提供商的连接字符串构建器。 Dim sqlBuilder As New SqlClient.SqlConnectionStringBuilder() ' 设置数据源的属性。 sqlBuilder.DataSource = Softlinks-PC sqlBuilder .InitialCatalog = RMS sqlBuilder.IntegratedSecurity = 错误 sqlBuilder.MultipleActiveResultSets = 真 ' 以避免异常,如果查询使用其他rquery内部 sqlBuilder.UserID = Softlinks-PC\Softlinks sqlBuilder.Password = 如果超时& gt; 0 然后 sqlBuilder.ConnectTimeout = timeout 结束 如果 返回 sqlBuilder.ToString 结束 功能 私人 Sub Form6_Load( ByVal sender 作为系统。对象, ByVal e As System.EventArgs)句柄 MyBase .Load 调用 SqlConn() Dim sql 作为 Str ing Dim ds = 新 DataSet Dim tables = ds.Tables Sql = SELECT * FROM Productitem da.Fill(ds, Productcode)' 将项目更改为您的数据库名称 Dim 视图作为 新 DataView(表格( 0 )) DataGridView1.DataSource = view 结束 Sub 结束 类 解决方案 您将da定义为对象并且永远不会给它一个值所以我不知道它如何编译并且在运行时不会出错。 删除顶部的da的声明在你的Load事件中做。 Dim da = 新 SqlDataAdapter 同时删除tables变量并改为执行此操作 Dim 视图作为 新 DataView(ds.Tables( 0 )) I am trying to display record in Datagridview1 with sql server but record does not display in Datagridview1 and there is no error in code.I hope you will solve this problem.RegardsMahmoodWhat I have tried:Public Class Form6 Dim da As Object Public Property ServerName() As String Public Property DatabaseName() As String Public Property Login() As String Public Property Password() As String Private Function SqlConn(Optional ByVal timeout As Integer = 0) As String ' Initialize the connection string builder for the ' underlying provider. Dim sqlBuilder As New SqlClient.SqlConnectionStringBuilder() ' Set the properties for the data source. sqlBuilder.DataSource = "Softlinks-PC" sqlBuilder.InitialCatalog = "RMS" sqlBuilder.IntegratedSecurity = False sqlBuilder.MultipleActiveResultSets = True 'to avoid exception if a query uses anothe rquery internal sqlBuilder.UserID = "Softlinks-PC\Softlinks" sqlBuilder.Password = "" If timeout > 0 Then sqlBuilder.ConnectTimeout = timeout End If Return sqlBuilder.ToString End Function Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Call SqlConn() Dim sql As String Dim ds = New DataSet Dim tables = ds.Tables Sql = "SELECT * FROM Productitem" da.Fill(ds, "Productcode") 'Change items to your database name Dim view As New DataView(tables(0)) DataGridView1.DataSource = view End SubEnd Class 解决方案 You are defining "da" as an object and never giving it a value so I don't know how this compiles and doesn't error when it runs.Remove your declaration of da at the top and do it in your Load event.Dim da = New SqlDataAdapterAlso remove the "tables" variable and do this insteadDim view As New DataView(ds.Tables(0)) 这篇关于记录未显示在datagridview1中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-17 21:13