此 SQL 数据表是否有任何解决方法?
Is there any workaround on this SQL Datatable?
我有这个运行良好的 CSharp WinForms 代码
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}
注意最后一行:if (virtualTable.Rows[0][1].ToString() == "Administrator")
在 C++/CLI 上应用相同的代码时,最后一行无法按预期工作。这是 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();
}
我收到以下错误:
但是每当我从这样的代码中删除 [1]
时都没有错误
有什么好的处理方法吗?
此致,
乔伊
参见here。根据post:
Seems a problem of IntelliSense, which does not stop the compilation and execution of the program.
虽然它确实为您停止了编译(也许我错了?)但我相信解决方法可能仍然适用。
根据给定的 link,针对您的情况建议的解决方法是:
DataRow ^ row = dtTable->Rows[0];
if (row[1]->ToString() == "Administrator")
{
this->Hide();
res_low->Show();
}
我发现的另一种解决方法是这样做
DataRow^ recAdmin = dtbaseData->Tables[0]->Rows[0];
if (recAdmin->IsNull("AdminId")) {
throw gcnew IndexOutOfRangeException("No such Admin Exist!");
} else{
MessageBox::Show("Login succsessfull");
res_load->Show();
this->Hide();
}
我有这个运行良好的 CSharp WinForms 代码
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}
注意最后一行:if (virtualTable.Rows[0][1].ToString() == "Administrator")
在 C++/CLI 上应用相同的代码时,最后一行无法按预期工作。这是 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();
}
我收到以下错误:
但是每当我从这样的代码中删除 [1]
时都没有错误
有什么好的处理方法吗?
此致,
乔伊
参见here。根据post:
Seems a problem of IntelliSense, which does not stop the compilation and execution of the program.
虽然它确实为您停止了编译(也许我错了?)但我相信解决方法可能仍然适用。
根据给定的 link,针对您的情况建议的解决方法是:
DataRow ^ row = dtTable->Rows[0];
if (row[1]->ToString() == "Administrator")
{
this->Hide();
res_low->Show();
}
我发现的另一种解决方法是这样做
DataRow^ recAdmin = dtbaseData->Tables[0]->Rows[0];
if (recAdmin->IsNull("AdminId")) {
throw gcnew IndexOutOfRangeException("No such Admin Exist!");
} else{
MessageBox::Show("Login succsessfull");
res_load->Show();
this->Hide();
}