作者kidnaper (弗卡夏)
看板C_Sharp
標題[程式] 抓取儲存格寫入新資料表!! [已解決]
時間Mon Mar 28 23:54:12 2011
小弟我最近研究儲存格的運用!!
目的是要抓取刪選後的儲存個在寫入新的表格內!!
範例與說明如下:
首先我先創造了一個名為 test 有 ITEM1,ITEM2欄位的表格
我要抓取dataGridView2的值寫入test之中
dataGridView2:
項目1 次數
紅豆 5
紅麴 6
麵包 6
橘子 5
我抓到test的結果為
ITEM1 ITEM2
紅豆 紅麴
紅豆 麵包
紅豆 橘子
紅麴 麵包
紅麴 橘子
.
.
.
以這樣的方式配對
我的程式碼如下:
string one, two;
int x, y;
for (x = 1; x <=6; x++)
dataGridView2.CurrentCell = dataGridView2[0, x];
one = string.Format("{0}", dataGridView2.CurrentCell.Value);
if (one == "")
{
break;
}
if (one != "")
{
for (y = x + 1; y <= 6; y++)
{
dataGridView2.CurrentCell = dataGridView2[0, x + 1];
two = string.Format("{0}", dataGridView2.CurrentCell.Value);
if (two == "")
{
reak;
}
if (two != "")
{
string putin = "";
putin = "insert into test(ITEM1,ITEM2) values(one,two) from test";
dataGridView2.DataSource = Dummy_DataTable3(putin, " ");
dataGridView2.AutoResizeColumns();
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.173.245.39
→ optimist9266:建議你用中斷點查看看,還有你程式碼貼這樣實在很難 03/29 01:37
→ optimist9266:看懂。 03/29 01:37
→ arcred:dataGridView2.DataSource = Dummy_DataTable3(putin 03/29 01:52
→ arcred:意味不明 03/29 01:53
→ kidnaper:抱歉那我修改一下好了 ^^" 03/29 14:13
※ 編輯: kidnaper 來自: 140.127.26.160 (03/29 14:25)
→ kidnaper:抱歉各位大大昨天寫完後po上,忘了檢查!! 03/29 14:26
各位大大我剛剛以找出正確解答了!! 上述程式碼可以執行結果!!
若有需要的人可以參考!! 若要刪除的話麻煩請通知^^感謝大家!!
※ 編輯: kidnaper 來自: 140.127.26.160 (03/29 20:46)