gpt4 book ai didi

c# - 'count' 中的未知列 'field list'

转载 作者:行者123 更新时间:2023-12-01 00:45:49 27 4
gpt4 key购买 nike

我尝试在 C# 中使用 MySQL 数据库创建一个登录表单,但出现此错误:“字段列表”中的未知列“计数”。我能做什么?

有错误的图片:

enter image description here

这是我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace ScoalaIT
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void pictureBox1_Click(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
string myConnection = "server=localhost;database=test;uid=root;password=123456";
MySqlConnection connection = new MySqlConnection(myConnection);


//string StrQuery1 = "Select count from users where user='" + txtUser.Text + "' and parola='" + txtParola.Text + "'";
MySqlCommand myCommand = new MySqlCommand("Select count from users where user='" + txtUser.Text + "' and parola='" + txtParola.Text + "'", connection);
//MySqlDataAdapter MyAdapter = new MySqlDataAdapter(myCommand);
MySqlDataReader myReader;
connection.Open();
myReader = myCommand.ExecuteReader();
int count = 0;
while (myReader.Read())
{
count++;
}
if (count == 1)
{
MessageBox.Show("Ok");
}
else
{
MessageBox.Show("Nu ok");
}
connection.Close();
}
}
}

谢谢!!!

最佳答案

改变这个...

"Select count from 

对于这个...

"Select count(*) from

然后阅读:http://en.wikipedia.org/wiki/SQL_injection因为你肯定会因此而受苦。

关于c# - 'count' 中的未知列 'field list',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22413683/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com