c++ CLI - C++ CLI 代码卡住了
c++ cli - C++ Cli code stucked
我删除了代码中不必要的部分,以阐明代码应该表示什么以及哪些代码实际上应该工作,因为我看到这会混淆引号文本中多余的空间。
MySqlDataReader^ myReader;
try
{
conDataBase -> Open();
myReader = cmdDataBase -> ExecuteReader();
// int count = 0;
while (myReader -> Read())
{
count = count + 1; // This piece of code I want to rewrite,from here to the bottom
// of the page,password should not be in the numbers but in the
// letters, and that's what I do not know how to do it.
// Statement if should be if (char*) or something like that.
}
if (count == 1)
{
MessageBox::Show ("Username and password are correct");
}
else if (count > 1)
{
MessageBox::Show ("Username and password are duplicates ... access denied!");
}
else
{
MessageBox::Show ("Username and password are incorrect ... Please enter your username and password!");
}
}
catch ( Exception^ ex)
{
MessageBox::Show(ex -> Message);
}
}
}
};
您提供的代码不适用于任何数字。
它唯一做的是
- 构造一些 SQL 查询
- 检查其结果
在 SQL 查询构造期间,代码不假定提供任何"数字"。它实际上使用一个名为password_txt->Text
的变量,这表明它是某种形式的TextBox
控制。代码从中获取"文本"并将其粘贴到查询中,没有任何假设。如果"文本"包含数字,它将粘贴数字。如果"文本"包含"mom_dad-and-MYDOG",代码将完全粘贴该内容。此外,代码已经确保文本将用引号(...' " + Text + " ' ...
)括起来,因此SQL语法对数字和文本都有效。
文本粘贴到查询中,无论是否确保引号,都会形成严重的安全问题。如果文本包含引号怎么办?你真的应该在这里使用 QueryParameters。这很严重,但这是一个完全不同的故事。请务必阅读有关它的信息。
回到数字/文本 - 所以,这段代码不关心"数字"。如果您的应用程序不允许密码为"文本",则原因必须位于代码的其他某个块中。
从那password_txt -> Text
来看,你可能有一个文本框或类似的东西。检查其events
部分。您很可能会找到一些 TextChanged 或 KeyPressed 或 KeyDown 事件处理程序,例如,这些处理程序将过滤掉除数字以外的所有按键。
编辑:另请查看 CrashMstr 建议的内容 - 删除我刚才提到的引号附近的多余空格。 ' 213 '
可能会强制使用 213,但' mom '
不会与表中的"妈妈"匹配。另一件事 - 确保检查数据库本身中password
列的数据类型;)
- 在 C++/CLI 中将 .NET 事件从一个 DLL 引发到另一个 DLL
- C++/CLI System.AccessViolation在托管类中调用非托管函数时出现异常
- 是否可以在Linux上使用.Net Core 3.1创建C++/CLI代码的C#DLL
- C++ DLL(不是 CLI)是否可以调用 .NET Core 3.0 委托?
- VS2010 C++ 调试托管 (C++/CLI) DLL
- 如何将 C++/CLI 库链接到C++应用程序
- C++/CLI targetting .NET Core 3.1
- 模板函数签名在 C++/CLI 中解包
- C++/CLI 混合托管/本机 DLL 不起作用
- C++/CLI 和 C#/VB 与不安全和外部有什么区别?
- 是否有可能构建面向Linux和Windows的.Net Core C++ / CLI应用程序?
- DirectX 12 和 C++ CLI :无法使用IID_PPV_ARGS
- 如何为要在 C# 中使用的静态库创建 C++ 或 C++/CLI 包装器
- 将 C# 对象(包含静态对象成员)作为参数传递给 C++/CLI 程序
- C++/CLI -- 访问结构成员
- 如何将字符串从 C++/CLI 方法返回到调用它的非托管C++
- 如何将CLI类的函数指针作为参数传递给C++方法
- 用于LabView中使用的本机c++的c++/cli dll包装器
- C#WPF和C++/CLI以及C++在C++/CLI中添加外部库错误
- 在.NET Core 3.1中运行托管C++/CLI程序集时,映像格式错误