记录不会显示在datagridview中 [英] Record not display in datagridview

查看:63
本文介绍了记录不会显示在datagridview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

记录不显示datagridview

但代码中没有错误

当表单打开时网格是空的没有记录

我的代码如下检查这个



我尝试过:



Record not display datagridview
but no error in code
when form will be open grid is empty no record
my code as under check this

What 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
                Dim sqlBuilder As New SqlClient.SqlConnectionStringBuilder()
 
                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")        
        Dim view As New DataView(ds.tables(0))
        DataGridView1.DataSource = view
    End Sub
 
End Class

推荐答案

正如我之前已经写过的,你缺少代码中的关键部分:

- 你没有打开与数据库的连接

- 你没有设置SQL任何地方声明

- 你不要在任何地方使用连接字符串等等...



所以请你拿一些时间并通过一些示例来说明如何填充数据集。这是一个开始: https://support.microsoft.com/en-us/kb/301216 [ ^ ]
As I already wrote earlier, you're missing key parts from your code:
- you don't open connection to the database
- you don't set the SQL statement anywhere
- you don't use the connection string anywhere and so on...

So please take some time and go through some examples how to populate a dataset. Here's one to start with: https://support.microsoft.com/en-us/kb/301216[^]

这篇关于记录不会显示在datagridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆