问题终于找到了,红色标记
SQL Server类型用_indentify会出错,显示列名无效,用_SortKey则可以
Access类型用_indentify和_SortKey都可以
Dim ss As New StringBuilder '定义长字符串
For Each cn As Connection In Connections '----------------------------------遍历数据源
'Output.Show("数据源名称:" & cn.Name)
'Output.Show("链接字符串:" & cn.ConnectionString)
Dim lst As List(Of String)
lst = Connections(cn.Name).GetTableNames '返加数据源的所有表集合
For Each nm As String In lst '------------------------------------------遍历表
'Output.Show("表名称:" & nm)
If cn.SourceType = 1 Then '----------------------------------Access类型,dc.ColumnName和dc.caption一样
Dim ada As New Data.OleDB.OleDbDataAdapter("Select * F rom " & nm & " Where [
_indentify] is null", cn.ConnectionString)
Dim dt As New Data.DataTable
ada.FillSchema (dt, System.Data.SchemaType.Source)
For Each dc As data.DataColumn In dt.Columns '------------------遍历列
'数据源|表名称|列名称|列类型|列长度---共5个
If dc.DataType.name = "String" Then '不能用dc.IsString
ss.Appendline(cn.Name & "|" & nm & "|" & dc.ColumnName & "|" & dc.DataType.name & "|" & dc.MaxLength) '字符串列+长度
Else
ss.Appendline(cn.Name & "|" & nm & "|" & dc.ColumnName & "|" & dc.DataType.name)
End If
Next
ElseIf cn.SourceType = 2 Then '------------------------------SQL Server类型,dc.ColumnName和dc.caption一样
Dim ada As New Data.OleDB.OleDbDataAdapter("Select * F rom " & nm & " Where [
_SortKey] is null", cn.ConnectionString)
Dim dt As New Data.DataTable
ada.FillSchema (dt, System.Data.SchemaType.Source)
For Each dc As data.DataColumn In dt.Columns '-------------------遍历列
'数据源|表名称|列名称|列类型|列长度---共5个
If dc.DataType.name = "String" Then '不能用dc.IsString
ss.Appendline(cn.Name & "|" & nm & "|" & dc.ColumnName & "|" & dc.DataType.name & "|" & dc.MaxLength) '字符串列+长度
Else
ss.Appendline(cn.Name & "|" & nm & "|" & dc.ColumnName & "|" & dc.DataType.name)
End If
Next
End If
Next
Next
Dim dlg As New SaveFileDialog '定义一个新保存文件对话框
dlg.Filter = "文本文件|*.txt" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
FileSys.WriteAllText(dlg.FileName, ss.Tostring, False, Encoding.Default) '保存为记事本文件
End If