2012-03-22 83 views
-2

我正在用C#編寫程序來將信息插入Access數據庫。因此,使用下面的C#語句和後繼表單,我需要知道我的Access字段必須是什麼數據類型。 (即; {0} = INT,{1} = NCHAR) 我認爲,直到我想通了,將C#結果存入Access數據庫 - 「其他信息:標準表達式中的數據類型不匹配」。

![string vsql = string.Format("insert into Log values " + 
     "('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", 
     comboBox1.Text,     //(type?) 
     comboBox2.Text,     //(type?) 
     int.Parse(textBox1.Text),  //I want this to be float (possible?) 
     int.Parse(textBox1.Text),  //I want this to be float (possible?) 
     textBox2.Text,     //(type?) 
     textBox3.Text,     //(type?) 
     addRemove);      //(type?) 

enter image description here

回答

1
string vsql = string.Format("insert into Log values " + 
     "('{0}','{1}',{2},{3},'{4}',#{5}#,'{6}')", 
     comboBox1.Text,   //string field 
     comboBox2.Text,   //string field 
     int.Parse(textBox1.Text), //don't wrap this in quotes if you want it as a float 
     int.Parse(textBox1.Text), //same as above 
     textBox2.Text,   //this is a DateTime field - you probably need to wrap with # marks. 
     textBox3.Text,   //string field 
     addRemove     //bool field 
     );  
+0

謝謝!這就像一個魅力! – Geo 2012-03-22 15:49:45

相關問題