質問編集履歴
3
コメントの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
```VB.net
|
21
21
|
Dim tablename as string 'Table名が入っています。
|
22
22
|
Dim getSchema as New DataTable
|
23
|
+
'DBの接続を行っています。接続成功したまたは接続済みの場合にTrueを返します。
|
23
24
|
If DBConnect() Then
|
24
25
|
'カラムの取得
|
25
26
|
Dim sql As String
|
2
コードの補足を行いました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,9 +3,13 @@
|
|
3
3
|
ODBCConnectionを利用して接続後に利用するテーブルの
|
4
4
|
DataTable型へとColumnやDataTypeなどを取得したいです。
|
5
5
|
|
6
|
-
テーブルのカラム一覧を取得し追加したDataTable型に
|
6
|
+
テーブルのカラム一覧を取得し追加したDataTable型のPrimaryKeyに
|
7
|
-
|
7
|
+
List(of DataColum)から値を代入を使用としています。
|
8
|
+
```VB.net
|
9
|
+
getSchema.PrimaryKey = getPrimaryKeylist(tablename).ToArray()
|
10
|
+
```
|
8
|
-
下記エラーが発生します。
|
11
|
+
そこで下記エラーが発生します。
|
12
|
+
|
9
13
|
> System.ArgumentException はユーザー コードによってハンドルされませんでした。
|
10
14
|
> HResult=-2147024809
|
11
15
|
> Message=列はテーブルに属していなければなりません。
|
@@ -14,6 +18,7 @@
|
|
14
18
|
|
15
19
|
下記コードです。
|
16
20
|
```VB.net
|
21
|
+
Dim tablename as string 'Table名が入っています。
|
17
22
|
Dim getSchema as New DataTable
|
18
23
|
If DBConnect() Then
|
19
24
|
'カラムの取得
|
@@ -22,6 +27,7 @@
|
|
22
27
|
"From INFORMATION_SCHEMA.COLUMNS " & _
|
23
28
|
"WHERE TABLE_NAME = '" & tablename & "' " & _
|
24
29
|
"Order by ORDINAL_POSITION "
|
30
|
+
'QueryExecuteは受け取ったQueryを実行して、結果をDataTableで返します。
|
25
31
|
Dim dtshema As DataTable = QueryExecuteReader(sql)
|
26
32
|
Dim col As DataColumn
|
27
33
|
For Each dtrow As DataRow In dtshema.Rows
|
@@ -35,11 +41,12 @@
|
|
35
41
|
|
36
42
|
sql = "select COLUMN_NAME from information_schema.constraint_column_usage " & _
|
37
43
|
"where table_name = '" & tableName & "' and constraint_name like 'PK_%'"
|
44
|
+
'QueryExecuteは受け取ったQueryを実行して、結果をDataTableで返します。
|
38
45
|
Dim dtPK As DataTable = QueryExecuteReader(sql)
|
39
46
|
For Each rowPK As DataRow In dtPK.Rows
|
40
47
|
getPrimaryKeylist.Add(New DataColumn(rowPK("COLUMN_NAME").ToString))
|
41
48
|
Next ' ここでエラー発生
|
42
|
-
getSchema.PrimaryKey = getPrimaryKeylist
|
49
|
+
getSchema.PrimaryKey = getPrimaryKeylist.ToArray()
|
43
50
|
Else
|
44
51
|
getSchema = Nothing
|
45
52
|
End If
|
1
タグの追加
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|