質問編集履歴

1

問題発生時のコードを追加

2020/07/25 02:37

投稿

boyon
boyon

スコア40

test CHANGED
File without changes
test CHANGED
@@ -39,3 +39,79 @@
39
39
 
40
40
 
41
41
  Visual Studio 2019 / .Net 4.7.2 を利用しています。
42
+
43
+
44
+
45
+ ```ここに言語を入力
46
+
47
+ DB2Connection con;
48
+
49
+ DB2DataReader reader = null;
50
+
51
+ private async void ButtonSelectAsync_Click(object sender, EventArgs e)
52
+
53
+ {
54
+
55
+ using (var cmd = con.CreateCommand())
56
+
57
+ {
58
+
59
+ cmd.CommandText = "SELECT文(省略)";
60
+
61
+ try
62
+
63
+ {
64
+
65
+ reader = await DB2ExecuteReaderAsync(cmd);
66
+
67
+ DataReaderを参照し画面に出す処理をここに書く();
68
+
69
+ }
70
+
71
+ catch (Exception ex)
72
+
73
+ {
74
+
75
+ MessageBox.Show(ex.Message);
76
+
77
+ }
78
+
79
+ }
80
+
81
+ }
82
+
83
+
84
+
85
+ private static async Task<DB2DataReader> DB2ExecuteReaderAsync(DB2Command cmd)
86
+
87
+ {
88
+
89
+ try
90
+
91
+ {
92
+
93
+ //非同期でSQLを実行
94
+
95
+ DB2DataReader readerAsync = null;
96
+
97
+ readerAsync = (DB2DataReader)await cmd.ExecuteReaderAsync;
98
+
99
+ return readerAsync;
100
+
101
+ }
102
+
103
+ catch (Exception ex)
104
+
105
+ {
106
+
107
+ MessageBox.Show(ex.Message);
108
+
109
+ return null;
110
+
111
+ }
112
+
113
+ }
114
+
115
+
116
+
117
+ ```