如何获取任何表sqlserver vb.net的所有元素?

时间:2017-03-30 07:58:20

标签: vb.net sql-server-2008

我试图使用此脚本获取表格的所有元素,但是当我点击确定时它没有显示任何内容......我不知道为什么。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim cmd13 As New SqlCommand
    Dim da13 As New SqlDataAdapter
    Dim dt13 As New DataTable
    Dim cn As New SqlConnection("Data source=.\SQLEXPRESS; Database=driving_school;Integrated Security=true")

    dt13.Clear()
    Dim StrsTables As String = "Table_1"
    Dim b As String = "SELECT c.name 'ColumnName', t.name + CASE WHEN t.name IN ('char', 'varchar','nchar','nvarchar') THEN '('+ CASE WHEN c.max_length=-1 THEN 'MAX' ELSE CONVERT(VARCHAR(4), CASE WHEN t.name IN ('nchar','nvarchar') THEN c.max_length/2 ELSE c.max_length END ) END +')' WHEN t.name IN ('decimal','numeric') THEN '('+ CONVERT(VARCHAR(4),c.precision)+ ',' + CONVERT(VARCHAR(4),c.Scale)+')' ELSE '' END as ""Data_Type"", convert(nvarchar,replace((replace(c.is_nullable,'0','NOT NULL')),'1','NULL')) as 'Nulle',c.is_identity as 'Inc' , ISNULL(i.is_primary_key, 0) 'PK' FROM sys.columns c INNER JOIN sys.types t ON c.user_type_id = t.user_type_id LEFT OUTER JOIN sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id LEFT OUTER JOIN sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id WHERE c.object_id = OBJECT_ID(1)"
    cmd13 = New SqlCommand(b, cn)
    da13 = New SqlDataAdapter(cmd13)
    da13.Fill(dt13)
    DataGridView1.DataSource = da13
End Sub

0 个答案:

没有答案