SQL语句出错解决方法
SQL语句出错for (i 0 i ListBox3-Items -Count i++){DataModule35-ADOQuery6-SQL-Add(insert
SQL语句出错
for (i = 0; i < ListBox3->Items ->Count; i++)
{
DataModule35->ADOQuery6->SQL->Add("insert into CardAuthor(CardNo,Author) values('" + Edit1->Text.Trim() + "','" + ListBox3->Items->Strings[ListBox3->Items[i]]+"')");
//DataModule35->ADOQuery6->SQL->Add(sql);
DataModule35->ADOQuery6->ExecSQL();
DataModule35->ADOQuery6->Close();
}
会在 DataModule35->ADOQuery6->SQL->Add("insert into CardAuthor(CardNo,Author) values('" + Edit1->Text.Trim() + "','" + ListBox3->Items->Strings[ListBox3->Items[i]]+"')");
这一次提示错误:[C++ Error] Unit3.cpp(699): E2034 Cannot convert 'TStrings' to 'int'
[C++ Error] Unit3.cpp(699): E2342 Type mismatch in parameter 'Index' (wanted 'int', got 'TStrings')
请问该怎么解决?
[最优解释]ListBox3->Items->Strings[ListBox3->Items[i]]
改成:
ListBox3->Items->Strings[i]
即可
[其他解释]int(ListBox3->Items->Strings[ListBox3->Items[i]]+");
[其他解释]ListBox3->Items[i]
下标怎么能放这个的。
[其他解释]你把DataModule35->ADOQuery6->SQL->Add("insert into CardAuthor(CardNo,Author) values('" + Edit1->Text.Trim() + "','" + ListBox3->Items->Strings[ListBox3->Items[i]]+"')");
换成:
DataModule35->ADOQuery6->SQL->Add(strTemp.sprintf("insert into CardAuthor(CardNo,Author) values('%s','%s')",Edit1->Text.Trim(),ListBox3->Items->Strings[i]]));
既简单,看的又明白
[其他解释]ListBox3->Items->Strings[i] 即可
[其他解释]1和4楼正解啊 楼主