读书人

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

发布时间: 2012-01-19 00:22:27 作者: rapoo

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 ') ";

读书人网 >C#

热点推荐