W
W
WasTabon2021-06-24 13:51:53
SQLite
WasTabon, 2021-06-24 13:51:53

"SQLite Error 1: 'near "on": syntax error'." what is this?

In the code, "on" is only in the lines, when I set the text to send telegrams to the bot, it is not connected at all
60d463102517d803543855.png

using System;
using System.Data;
using Microsoft.Data.Sqlite;
using Telegram;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups;


namespace TelegramSQLBotv2
{
    class Program
    {
        static SqliteConnection connection = new SqliteConnection("Data Source=usersdata.db");
        static TelegramBotClient client = new TelegramBotClient("123");
        static void Main(string[] args)
        {
            client.OnMessage += BotOnMessage; 
            client.StartReceiving(); 
            Console.ReadKey();
            client.StopReceiving();
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
            }
        }
        async static void BotOnMessage(object sender, MessageEventArgs e)
        {
            Message msg = e.Message; //создаём переменную, которая содержит все свойства сообщения
            ParseMode parseMode = ParseMode.Markdown; // Позволяет делать жирный текст и т.п

            #region Keyboards

            var CommonUserKeyboard = new ReplyKeyboardMarkup()
            {
                Keyboard = new[]
                    {
                        new[]
                        {
                            new KeyboardButton("123"),
                            new KeyboardButton("123"),
                        }
                    }
            }; 

            var CommonUserLogin = new ReplyKeyboardMarkup()
            {
                Keyboard = new[]
                   {
                        new[]
                        {
                            new KeyboardButton("Пройти капчу "),
                        }
                    }
            }; /

            #endregion

            #region MainMethods

            if (msg.Text == "/createDB")
            {
                connection.Open();
                SqliteCommand command = new SqliteCommand();
                command.Connection = connection;
                command.CommandText = "CREATE TABLE  MainDataBase(_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, M TEXT NULL)";
                command.ExecuteNonQuery();
                Console.WriteLine("Таблица MainDataBase создана");
                connection.Close();
            } // Созданние базы данных

            if (msg.Text == "/start")
            {
                CommonUserLogin.ResizeKeyboard = true;
                await client.SendTextMessageAsync(msg.Chat.Id, $"Здравствуйте, *{msg.Chat.FirstName}*. Чтобы продолжить - нажмите на кнопку " + "Пройти капчу ", parseMode, replyMarkup: CommonUserLogin);
            } // Первое сообщение

            if (msg.Text == "Пройти капчу ")
            {
                CommonUserKeyboard.ResizeKeyboard = true;
                bool same = false;
                connection.Open();
                string sqlExpression = "SELECT * FROM MainDataBase";
                SqliteCommand command = new SqliteCommand(sqlExpression, connection);
                SqliteDataReader reader = command.ExecuteReader();
                while (reader.Read()) // построчно считываем данные
                {
                    object id = reader.GetValue(0);
                    if (id.ToString() == msg.Chat.Id.ToString())
                    {
                        same = true;
                    }
                }
                reader.Close();
                if (same == true)
                {
                    await client.SendTextMessageAsync(msg.Chat.Id, $"Приветствуем вас снова, пользователь *{msg.Chat.Id}*.", parseMode, replyMarkup: CommonUserKeyboard);
                }
                else
                {
                    SqliteCommand command2 = new SqliteCommand();
                    command.Connection = connection;
                    command.CommandText = $"INSERT INTO MainDataBase (_id, M) VALUES ({msg.Chat.Id.ToString()}, {msg.Chat.FirstName})";
                    command.ExecuteNonQuery();
                    Console.WriteLine($"Новый юзер - {msg.Chat.FirstName}");
                    await client.SendTextMessageAsync(msg.Chat.Id, $"Капча пройдена и аккаунт с id *{msg.Chat.Id}* успешно создан", parseMode, replyMarkup: CommonUserKeyboard);
                }
                connection.Close();
            }
            #endregion

        }

    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-06-24
@WasTabon

I forgot the quotation marks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question