質問編集履歴
2
a
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
削除しま
|
1
|
+
一旦削除致します。一旦削除致します。一旦削除致します。一旦削除致します。一旦削除致します。一旦削除致します。一旦削除致します。一旦削除致します。一旦削除致します。一旦削除致します。一旦削除致します。一旦削除致します。一旦削除致します。一旦削除致します。一旦削除致します。
|
1
あ
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,165 +1,1 @@
|
|
1
|
-
お世話になります。
|
2
|
-
|
3
|
-
dataGridViewの内容をCSV出力したいです。
|
4
|
-
色々調べたのですがうまくいかず、どなたかご教示のほどよろしくお願い致します。
|
5
|
-
|
6
|
-
``````ここに言語を入力
|
7
|
-
using System;
|
8
|
-
using System.Collections.Generic;
|
9
|
-
using System.ComponentModel;
|
10
|
-
using System.Data;
|
11
|
-
using System.Drawing;
|
12
|
-
using System.Linq;
|
13
|
-
using System.Text;
|
14
|
-
using System.Threading.Tasks;
|
15
|
-
using System.Windows.Forms;
|
16
|
-
using System.Data.SQLite;
|
17
|
-
using System.Windows;
|
18
|
-
|
19
|
-
|
20
|
-
namespace WindowsFormsApplication4
|
21
|
-
{
|
22
|
-
public partial class Itiran : Form
|
23
|
-
{
|
24
|
-
public Itiran()
|
25
|
-
{
|
26
|
-
InitializeComponent();
|
27
|
-
}
|
28
|
-
#region 画面遷移制御
|
29
|
-
private void btnsintou_Enter(object sender, EventArgs e)
|
30
|
-
{
|
31
|
-
//新規登録ボタンを押下すると登録画面に遷移
|
32
|
-
Touroku Touroku = new Touroku();
|
33
|
-
Touroku.Show();
|
34
|
-
this.Visible = false;
|
35
|
-
}
|
36
|
-
#endregion
|
37
|
-
|
38
|
-
private DataTable datatable = new DataTable();
|
39
|
-
protected override void OnLoad(EventArgs e)
|
40
|
-
{
|
41
|
-
dataGridView1.DataSource = datatable;
|
42
|
-
base.OnLoad(e);
|
43
|
-
}
|
44
|
-
//テーブルの内容を表示
|
45
|
-
private void buttonkensaku_Click(object sender, EventArgs e)
|
46
|
-
{
|
47
|
-
//検索条件がない場合
|
48
|
-
if (txtSiteNm.Text == "")
|
49
|
-
{
|
50
|
-
//using (SQLiteConnection con = new SQLiteConnection("Data Source = C"))
|
51
|
-
using (SQLiteConnection con = new SQLiteConnection("Data Source = C"))
|
52
|
-
|
53
|
-
|
1
|
+
削除しました削除しました削除しました削除しました削除しました削除しました削除しました削除しました削除しました削除しました削除しました削除しました削除しました削除しました削除しました削除しました削除しました削除しました
|
54
|
-
{
|
55
|
-
//データグリッドビューのクリア
|
56
|
-
datatable.Clear();
|
57
|
-
|
58
|
-
dataGridView1.DataSource = datatable;
|
59
|
-
adapter.Fill(datatable);
|
60
|
-
|
61
|
-
//dataGridView1.Columns[0].HeaderText = "ID";
|
62
|
-
//No,SiteNm,LoginId,Password,BIKO カラム順
|
63
|
-
//テーブルの内容表示
|
64
|
-
dataGridView1.Columns[0].HeaderText = "No";
|
65
|
-
dataGridView1.Columns[1].HeaderText = "サイト名";
|
66
|
-
dataGridView1.Columns[2].HeaderText = "ログインIDまたはEmail等";
|
67
|
-
dataGridView1.Columns[3].HeaderText = "パスワード";
|
68
|
-
dataGridView1.Columns[4].HeaderText = "登録日";
|
69
|
-
dataGridView1.Columns[5].HeaderText = "備考";
|
70
|
-
|
71
|
-
}
|
72
|
-
}
|
73
|
-
else
|
74
|
-
{
|
75
|
-
string dbConnectionString = "Data Source = C:\\Users/Takaaki Kawabe/Desktop/WindowsFormsApplication4 /myfriend.sqlite3";
|
76
|
-
using (SQLiteConnection cn = new SQLiteConnection(dbConnectionString))
|
77
|
-
{
|
78
|
-
cn.Open();
|
79
|
-
using (SQLiteTransaction trans = cn.BeginTransaction())
|
80
|
-
{
|
81
|
-
SQLiteCommand cmd = cn.CreateCommand();
|
82
|
-
//DBセレクト
|
83
|
-
cmd.CommandText = "SELECT * from PASS_KANRI where SiteNm = @SiteNm";
|
84
|
-
|
85
|
-
//パラメータセット
|
86
|
-
cmd.Parameters.Add("SiteNm", System.Data.DbType.String);
|
87
|
-
|
88
|
-
cmd.Parameters["SiteNm"].Value = txtSiteNm.Text;
|
89
|
-
|
90
|
-
//datatableのクリア
|
91
|
-
datatable.Clear();
|
92
|
-
//datatableに検索結果をセット
|
93
|
-
datatable.Load(cmd.ExecuteReader());
|
94
|
-
|
95
|
-
dataGridView1.DataSource = datatable;
|
96
|
-
|
97
|
-
//dataGridView1.Columns[0].HeaderText = "ID";
|
98
|
-
//No,SiteNm,LoginId,Password,BIKO カラム順
|
99
|
-
//テーブルの内容表示
|
100
|
-
dataGridView1.Columns[0].HeaderText = "No";
|
101
|
-
dataGridView1.Columns[1].HeaderText = "サイト名";
|
102
|
-
dataGridView1.Columns[2].HeaderText = "ログインID";
|
103
|
-
dataGridView1.Columns[3].HeaderText = "パスワード";
|
104
|
-
dataGridView1.Columns[4].HeaderText = "登録日";
|
105
|
-
dataGridView1.Columns[5].HeaderText = "備考";
|
106
|
-
trans.Commit();
|
107
|
-
cn.Close();
|
108
|
-
}
|
109
|
-
}
|
110
|
-
}
|
111
|
-
}
|
112
|
-
/// <summary>
|
113
|
-
///
|
114
|
-
/// </summary>
|
115
|
-
/// <param name="sender"></param>
|
116
|
-
/// <param name="e"></param>
|
117
|
-
private void dataGridView1_Validating(object sender, CancelEventArgs e)
|
118
|
-
{
|
119
|
-
//Clipboard.SetDataObject(dataGridView1.GetClipboardContent());
|
120
|
-
//ヘッダーをコピーしないようにする
|
121
|
-
//dataGridView1.ClipboardCopyMode =
|
122
|
-
// DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
|
123
|
-
//選択されたセルの内容をクリップボードへコピー
|
124
|
-
//Clipboard.SetDataObject(dataGridView1.GetClipboardContent());
|
125
|
-
}
|
126
|
-
|
127
|
-
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
|
128
|
-
{
|
129
|
-
//DataGridViewの内容をコピー
|
130
|
-
Clipboard.SetDataObject(dataGridView1.GetClipboardContent());
|
131
|
-
}
|
132
|
-
|
133
|
-
private void Itiran_Load(object sender, EventArgs e)
|
134
|
-
{
|
135
|
-
|
136
|
-
}
|
137
|
-
#region Enter制御
|
138
|
-
private void Itiran_KeyDown(object sender, KeyEventArgs e)
|
139
|
-
{
|
140
|
-
|
141
|
-
//Enterキーでコントロール遷移
|
142
|
-
if (e.KeyCode == Keys.Enter)
|
143
|
-
{
|
144
|
-
if (e.Shift)
|
145
|
-
{
|
146
|
-
ProcessTabKey(false);
|
147
|
-
}
|
148
|
-
else
|
149
|
-
{
|
150
|
-
ProcessTabKey(true);
|
151
|
-
}
|
152
|
-
}
|
153
|
-
}
|
154
|
-
#endregion
|
155
|
-
private void btncsv_Click(object sender, EventArgs e)
|
156
|
-
{
|
157
|
-
#region CSVに出力
|
158
|
-
|
159
|
-
|
160
|
-
#endregion
|
161
|
-
}
|
162
|
-
}
|
163
|
-
}
|
164
|
-
|
165
|
-
```
|