从arraylist插入数据库值

时间:2014-02-11 14:42:16

标签: c# database arraylist insert

平台c# degerler kutu是数据库表的列名。 kutular是来自形式的控制名称, 我想从arraylist插入记录到数据库,帮助:)如何运行此代码?

Control[] kutular = {Sirket_Unvani, Vergi_Daire, Vergi_No, yetkili, 
                     Yetkili_Telefon, Telefon, faks, adres, CariDosyaadi };

string[] degerlerkutu = { "Sirket_Unvani", "Vergi_Daire", "Vergi_No", "yetkili", 
 "Yetkili_Telefon", "Telefon", "faks", "adres" ,"il" , "ilce", "CariDosyaadi" };

ComboBox[] Combolar = { il, ilce };

ArrayList kaynak = new ArrayList();
ArrayList hedef = new ArrayList();
kaynak.Clear();
hedef.Clear();

for (int i = 0; i < kutular.Count(); i++)
{
    kaynak.Add(kutular[i].Name +".Text");  
}

for (int i = 0; i < Combolar.Count(); i++)
{
    kaynak.Add(Combolar[i].Name+".SelectedValue"); 
}

for (int i = 0; i < degerlerkutu.Count(); i++)
{
    hedef.Add(degerlerkutu[i]);
}

OleDbCommand cmd2 = 
       new OleDbCommand(@"INSERT INTO cariler (" + string.Join(",", hedef) 
               + ") Values (" + string.Join(",",kaynak) + ")", anafrm.bag);

cmd2.ExecuteNonQuery();

1 个答案:

答案 0 :(得分:0)

我看到的第一件事是你需要在字符串周围加上单引号。希望这有帮助!

值('“+ string.Join(”','“,kaynak)+”')“