首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#中数据库的Insert有关问题

2012-01-19 
C#中数据库的Insert问题下面的VALUES(s[i]出错,到底是什么问题啊?string[]snewstring[30]intf0for(int

C#中数据库的Insert问题
下面的VALUES   (   s[i]出错,到底是什么问题啊?

string[]   s   =   new   string[30];
                        int   f   =   0;
                        for   (int   i   =   0;   i   <   6;   i++)
                        {
                                for   (int   j   =   i   +   1;   j   <   6;   j++)
                                {
                                        Immunity(i,   j);
                                        s[f]   =   ArrayToString(c);
                                        f++;
                                        Immunity(j,   i);
                                        s[f]   =   ArrayToString(c);
                                        f++;
                                }
                        }

                        try
                        {
                                string   connString   =   @ "
                                provider   =   microsoft.jet.oledb.4.0;          
                                data   source   =   E:\课件\人工免疫系统在计算机病毒检测中的应用研究-datalistview\人工免疫系统在计算机病毒检测中的应用研究\Immunity.mdb;
                                ";
                                OleDbConnection   Conn   =   new   OleDbConnection(connString);
                                Conn.Open();
                                for   (int   i   =   0;   i   <   30;   i++)
                                {
                                        string   strInsert   =   "   INSERT   INTO   Immunity   (   code   ,   status   ,   bond   ,   times   ,   age   )   VALUES   (   s[i], '未成熟检测器 ', '0 ', '0 ', '1 ') ";


                                        OleDbCommand   inst   =   new   OleDbCommand(strInsert,   Conn);
                                        inst.ExecuteNonQuery();
                                }
                                this.immunityTableAdapter.Fill(this.immunityDataSet.immunity);
                                Conn.Close();
                        }
                        catch   (Exception   error)
                        {
                                MessageBox.Show( "连接数据库发生错误为: "   +   error.ToString(),   "错误! ");
                        }  


[解决办法]
try

string strInsert = " INSERT INTO Immunity ( code , status , bond , times , age ) VALUES ( ' " + s[i] + " ', '未成熟检测器 ', '0 ', '0 ', '1 ') ";
[解决办法]
string strInsert = " INSERT INTO Immunity ( code , status , bond , times , age ) VALUES ( s[i], '未成熟检测器 ', '0 ', '0 ', '1 ') ";
=> >
string strInsert = " INSERT INTO Immunity ( code , status , bond , times , age ) VALUES ( ' "+ s[i] + " ', '未成熟检测器 ', '0 ', '0 ', '1 ') ";

热点排行