c# - 如何解决 Wpf System.Data.SqlClient.SqlException 中的以下错误:“'System.Windows.Controls.PasswordBox'附近的语法不正确。”
问题描述
我创建了一个 wpf(.net framework) 应用程序供用户登录,但我不断收到此错误:System.Data.SqlClient.SqlException: 'System.Windows.Controls.PasswordBox' 附近的语法不正确。
这是我的代码:
private void Button_Click_2(object sender, RoutedEventArgs e)
{
string mainconn = "Data Source=VCPTCR4PC19\\SQLEXPRESS;Initial Catalog=TASK2;Integrated Security=True";
SqlConnection conn = new SqlConnection(mainconn);
conn.Open();
string cmds = $" Select * from USERS (@USERS_NAME, @USERS_PASSWORD ) ";
SqlCommand command = new SqlCommand(cmds, conn);
command.Parameters.Add("@USERS_NAME", SqlDbType.VarChar).Value= txtUsername.Text;
command.Parameters.Add("@USERS_PASSWORD", SqlDbType.VarChar).Value = HashCode.PassHash(password.Password);
SqlDataAdapter sqlData = new SqlDataAdapter("Select Count(*) From USERS Where USER_NAME = '" + txtUsername + "'and PASSWORD'" + password + "'", conn);
DataTable dataTable = new DataTable();
sqlData.Fill(dataTable);
if (dataTable.Rows[0][0].ToString() == "1")
{
this.Hide();
Modules modules = new Modules();
modules.ShowDialog();
}
else
{
MessageBox.Show("Invaild user name or password enterd");
}
conn.Close();
}
解决方案
推荐阅读
- html - 如何将 Ionic 日期时间选择器定位到屏幕顶部?
- html - 缩放转换时列中的 CSS 元素位于上边框下方
- python - How can i remove double quotes in cmd title
- cassandra - Cassandra,如果集合包含值则删除
- android - 为小部件布局触发 Android 10 主题更新
- python - 无法 pipenv 从源代码(pypi)安装 confluent-kafka 1.4.0 - 似乎没有解决方法有效
- r - 关于 R 中 LFE 包中具有聚集标准误差的 p 值的问题
- powershell - Powershell 在 URL 中为 RestMethod 编码 JSON 数组
- html - 有没有办法将我的网页从 Bubble 导出到不同的服务器?
- javascript - PHP Laravel 自定义排序按最终和更好的时间