Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SqlException是未处理的错误_C#_.net - Fatal编程技术网

C# SqlException是未处理的错误

C# SqlException是未处理的错误,c#,.net,C#,.net,我越来越 SqlException是未处理的错误 运行程序时显示消息。下面是我的VisualStudio中的所有代码,并检查附加图像中的错误消息屏幕截图 请帮我找到解决这个问题的方法。我哪里做错了 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System

我越来越

SqlException是未处理的错误

运行程序时显示消息。下面是我的VisualStudio中的所有代码,并检查附加图像中的错误消息屏幕截图

请帮我找到解决这个问题的方法。我哪里做错了

 using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Data.SqlClient;

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

            private void button1_Click(object sender, EventArgs e)
            {
                this.Close();
            }

            private void button2_Click(object sender, EventArgs e)
            {
                SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-V05BRHA\SQLEXPRESS;Initial Catalog=LoginSystem;Integrated Security=True;Pooling=False;");
                SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) From Tables where UserName='"+ textBox1.Text + "' and Password='" + textBox2.Text + "'",con);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                if (dt.Rows[0][0].ToString() == "1")
                {

                this.Hide();
                Main ss = new Main();
                ss.Show();
                }
                else
                {
                    MessageBox.Show("Please enter your username and password");
                }
            }
        }
    }

数据库中没有表。您能从中修改您的查询吗

Select Count(*) From Tables


此外,我建议将表重命名为User或Login。最好保留有意义的表名。

无效的对象名“tables”-您的数据库中有tables表吗?有时我想知道为什么有人想用这种方式自杀。您的表名为table而不是TABLES。现在,在修复错误后,开始询问代码为什么会出现语法错误。表是一个保留关键字。你能把你的“表”改名为更有意义的吗?这里有太多的错误,完整的答案需要一篇博客文章:一个快速检查表1)表而不是表(问题最少),2)硬编码连接字符串(在其他机器上永远不会工作)3)Pooling=false(天哪,为什么?)4)字符串连接(Bobby Tables很乐意加入)5)Adapert fill检索标量值?(无用的性能攻击)6)明文密码?(同样,黑客会非常高兴)7)无法处理连接之类的对象(系统资源泄漏)。
Select Count(*) From Table