0
我無法將DataTable中的數據導入到DataGridView中。我在Visual Basic中找到了代碼,並嘗試將它轉換爲Visual C++。將MySQL搜索查詢複製到數據表中
String^ cninfo = "server=localhost; port=3306; username=test; password=Lalala123; database=turismo";
MySqlConnection^ cn = gcnew MySqlConnection;
MySqlDataAdapter^ cmdadp;
DataTable^ Table = gcnew DataTable;
String^ search = searchtxt->Text;
int^ rowposition = 0;
String^ id_searchQuery = ("select * from clientes where CLIENT_ID = @search;");
String^ name_searchQuery = ("select * from clientes where FIRST_NAME like '%@search%';");
String^ lastname_searchQuery = ("select * from clientes where LAST_NAME like '%@search%';");
String^ origin_searchQuery = ("select * from clientes where COUNTRY_ORIGIN like '%@search%';");
if (radid /*Radbutton for id_searchQuery*/->Checked == true) {
cn->ConnectionString = cninfo;
cn->Open();
//defining parameters for the search query
MySqlCommand^ searchCmd = gcnew MySqlCommand(id_searchQuery, cn);
searchCmd->CommandType = CommandType::Text;
searchCmd->Parameters->AddWithValue("@search", search);
//filling the DataTable with MySqlDataAdapter
cmdadp->Fill(Table);
//counting each DataTale line to enter it into a DataGridView with a while function
while (rowposition < Table->Rows->Count) {
DataRow^ MyDataRow = Table->Rows(rowposition);
}
cn->Close();
}
在(rowposition < Table->Rows->Count) {
我得到的 「<」 強調,我也得到
無操作 「<」 匹配這些命令
而且在DataRow^ MyDataRow = Table->Rows(rowposition);
我得到突出顯示 「表」 和我獲取
調用對象o ˚F沒有apropriate運營商()或轉換函數的句柄類型指針到函數類型
,如果你只需要聲明'rowposition'作爲'int'而不是'INT會發生什麼^'? –
運算符的第一個錯誤得到修復,但第二個錯誤沒有得到任何結果 –
'Table-> Rows'的類型是[DataRowCollection Class](https://msdn.microsoft.com/en-us/library/system.data.datarowcollection( v = vs.110)的.aspx)。嘗試使用'Item'屬性數組表示法訪問該行,例如'Table-> Rows [rowposition]'。 –