[問題] C#與資料庫連結!!
我前陣子問了 宣告數字型態變數於刪除指定的問題!!
後解決的敘述為下:
private void button3_Click(object sender, EventArgs e)
{
string selectCmb = "";
int KeyIN = int.Parse(textBox2.Text);
selectCmb = "DELETE FROM data WHERE 學號="+KeyIN;
dataGridView1.DataSource = Dummy_DataTable(selectCmb, "data");
dataGridView1.AutoResizeColumns();
}
而後我再練習增新功能:
private void button4_Click(object sender, EventArgs e)
{
string Keyin;
string key1 = "";
string key2 = "";
string key3 = "";
key1 = textBox3.Text;
key2 = textBox4.Text;
key3 = textBox5.Text;
Keyin="Insert into data (學號,姓名,居住縣市) values ('"+key1+"' ,'"+key2+"','"+key3+"' )" ;
dataGridView1.DataSource = Dummy_DataTable(Keyin, "data");
dataGridView1.AutoResizeColumns();
}
很快的就寫完了!! 但是我這本增新的學號key1 資料屬於字串類型
PS:我將程式改為:
private void button4_Click(object sender, EventArgs e)
{
string Keyin;
int key1 = int.Parse(textBox3.Text);
string key2 = "";
string key3 = "";
key2 = textBox4.Text;
key3 = textBox5.Text;
Keyin="Insert into data (學號,姓名,居住縣市) values ("+key1+" ,'"+key2+"','"+key3+"' )" ;
dataGridView1.DataSource = Dummy_DataTable(Keyin, "data");
dataGridView1.AutoResizeColumns();
}
結果依然一樣
我想請問一下!!
1.我該怎麼增新的資料中 僅有學號這個資料是數字類型!!
我希望學號是數字類型資料的原因是希望它能夠被按照順序被排序!!
謝謝大家!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.127.27.231
→
12/27 15:06, , 1F
12/27 15:06, 1F
→
12/27 15:19, , 2F
12/27 15:19, 2F
→
12/27 15:22, , 3F
12/27 15:22, 3F
→
12/27 15:45, , 4F
12/27 15:45, 4F
→
12/27 15:45, , 5F
12/27 15:45, 5F
→
12/27 15:49, , 6F
12/27 15:49, 6F
→
12/27 15:49, , 7F
12/27 15:49, 7F
→
12/27 15:55, , 8F
12/27 15:55, 8F
→
12/27 17:06, , 9F
12/27 17:06, 9F