Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.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# C:我在尝试使用ExecuteScalar时遇到以下错误:“没有与此命令关联的连接”_C#_Sql_Sqlite_Executescalar - Fatal编程技术网

C# C:我在尝试使用ExecuteScalar时遇到以下错误:“没有与此命令关联的连接”

C# C:我在尝试使用ExecuteScalar时遇到以下错误:“没有与此命令关联的连接”,c#,sql,sqlite,executescalar,C#,Sql,Sqlite,Executescalar,我试图使用ExecuteScalar将数据库中的信息保存到一个变量中,但每次都会出现错误No connection与此命令关联 我已经为同一个应用程序创建了一个登录表单,该应用程序连接到同一个数据库,并且可以正常工作。所以我不知道连接是否有问题 SetConnection(); sql_con.Open(); SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Tisc

我试图使用ExecuteScalar将数据库中的信息保存到一个变量中,但每次都会出现错误No connection与此命令关联

我已经为同一个应用程序创建了一个登录表单,该应用程序连接到同一个数据库,并且可以正常工作。所以我不知道连接是否有问题

        SetConnection();
        sql_con.Open();        
        SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Tische WHERE Tischnummer = 54 AND Reservierung = 0");
        int reader = Convert.ToInt32(cmd.ExecuteScalar());
        cmd.Dispose();
        sql_con.Close();


        if (reader == 0)
        {
            string message = "Wollen Sie den Tisch reservieren?";
            string caption = "Reservation";
            MessageBoxButtons buttons = MessageBoxButtons.YesNo;
            DialogResult result;
            result = MessageBox.Show(message, caption, buttons);
            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                pictureBox54.Visible = false;
                pictureBox6.Visible = true;
                ;
            }
        }
        else
        {
            MessageBox.Show("Dieser Tisch ist bereits Reserviert!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            
        }
    

SQLiteCommand cmd=new SQLiteCommandSELECT*来自Tische,其中Tischnummer=54,ReserveRung=0,sql\u con;或者sql_con.CreateCommand,也不要忘记使用块处理连接和命令