SQLinfo.ru - Все о MySQL

Форум пользователей MySQL

Задавайте вопросы, мы ответим

Вы не зашли.

#1 04.05.2021 00:40:44

xamelione25
Участник
Зарегистрирован: 04.05.2021
Сообщений: 1

Ошибка: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Ошибка выскакивает в adapter.Fill(table); (35 строка).
После попытки выбора второй строки ... или при попытке изменения выбранного пункта в первой строке ... В datagridview1 - см строки 54-68
Думал проблема связана с MySQL - переустановил - не помогло.

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 AdvancedWizardControl.Wizard;
using AdvancedWizardControl.WizardPages;
using AdvancedWizardControl.Enums;
using AdvancedWizardControl.EventArguments;
using AdvancedWizardControl;
using Dapper;
using MySql.Data.MySqlClient;
using System.Diagnostics;
using System.IO;
 
namespace IT_A_stroy
{
    public partial class WizardPageEventArgs : Form
    {
        public int PreviousPage { get; set; }
        //DataSet ds;
        MySqlDataAdapter adapter;
        readonly string connectionString = "server=localhost;user=root;database=a_stroy;password=q1w2e3r4t5y6u7i8o9p0;";
        //string sql_1 = "select Progess, Progress_info from a_stroy.step3 where 1=2";
        public DataTable Execute(string script)
        {
            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                DataTable table = new DataTable();
                connection.Open();
                adapter = new MySqlDataAdapter(script, connection);
                adapter.Fill(table);
                return table;
            }
        }
 
        private void СomboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            if (comboBox1.SelectedValue != null)
            {
                column1.DataSource = Execute($"SELECT id_Object, id_customer, Name_object FROM a_stroy.object where id_customer = {comboBox1.SelectedValue};");
                column1.DisplayMember = "Name_object";
                column1.ValueMember = "id_Object";
                int countRow = dataGridView1.RowCount == 1 ? 1 : dataGridView1.RowCount - 1;
                //int DGV1 = comboBox1.SelectedIndex;
                //ds.Tables["step3"].Rows.Add(countRow);
            }
        }
 
        private void DataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            ComboBox cbDgv = e.Control as ComboBox;
            cbDgv.SelectedValueChanged -= CbDgv_SelectedValueChanged;
            cbDgv.SelectedValueChanged += CbDgv_SelectedValueChanged;
        }
 
        private void CbDgv_SelectedValueChanged(object sender, EventArgs e)
        {
            ComboBox box = sender as ComboBox;
            Debug.WriteLine(box.SelectedValue);
            column2.DataSource = Execute($"SELECT id_Object, Name_works FROM a_stroy.words_object where id_Object = {box.SelectedValue}");
            column2.DisplayMember = "Name_works";
            column2.ValueMember = "id_Object";
        }
 
        private void DataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           //
        }
 ...
       


Прикрепленные файлы:
Attachment Icon Screenshot_11.jpg, Размер: 145,246 байт, Скачано: 182

Неактивен

 

Board footer

Работает на PunBB
© Copyright 2002–2008 Rickard Andersson