I have this CSharp WinForms code that works well
SqlConnection loginCon = new SqlConnection
("Data Source=MORTDECAI;Initial Catalog=d_Authentication;Integrated Security=True;Pooling=False;");
SqlCommand connectionCommand = new SqlCommand
("Select * From d_Info where Username=@username COLLATE Latin1_General_CS_AS and Password=@password COLLATE Latin1_General_CS_AS", loginCon);
connectionCommand.Parameters.AddWithValue("@username", textUsername.Text);
connectionCommand.Parameters.AddWithValue("@password", textPassword.Text);
connectionCommand.Connection = loginCon;
loginCon.Open();
SqlDataAdapter adaptData = new SqlDataAdapter(connectionCommand);
DataSet databaseData = new DataSet();
DataTable virtualTable = new DataTable();
adaptData.Fill(databaseData, "Login");
virtualTable = databaseData.Tables["Login"];
loginCon.Close();
int count = databaseData.Tables[0].Rows.Count;
if (count == 1)
{
if (virtualTable.Rows[0][1].ToString() == "Administrator"){
//some codes}
Notice the last line: if (virtualTable.Rows[0][1].ToString() == "Administrator")
When the same code is applied on C++/CLI, the last line doesn't work as intended. Here is the code in C++/CLI
adaptData->Fill(dtbaseData, "AdminTable");
dtTable = dtbaseData->Tables["AdminTable"];
Database->Close();
sqlCount = dtbaseData->Tables[0]->Rows->Count;
if (sqlCount == 1) {
if (dtTable->Rows[0][1]->ToString() == "Administrator") {
this->Hide();
res_load->Show();
}
I get the following error:
but there is no error whenever I removed [1]
from the code like this
Is there any good way in handling this error?
Regards,
Joey
See here. According to that post:
Seems a problem of IntelliSense, which does not stop the compilation and execution of the program.
While it does appear to stop compilation for you (maybe I'm wrong?) I believe the workaround may still apply.
The suggested workaround in your case, based on the link given, would be:
DataRow ^ row = dtTable->Rows[0];
if (row[1]->ToString() == "Administrator")
{
this->Hide();
res_low->Show();
}