C
C
Chipu2018-09-06 17:55:09
MySQL
Chipu, 2018-09-06 17:55:09

C#, System.InvalidOperationException is thrown when interacting with the database. How to fix?

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 MySql.Data.MySqlClient;

namespace bd_test_program
{
    
    public partial class Form1 : Form
    {
        
        public static string constr = "server =31.31.196.8; user id =tytid; password =tytpass; persistsecurityinfo = True; port =3306; database =u0558875_default; SslMode = none";
        public MySqlConnection conn = new MySqlConnection(constr);
        

        public Form1()
        {
            InitializeComponent();
            conn.Open();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
        }

        private void vxod(object sender, EventArgs e)
        {

            string login = textBox1.Text;
            string password = textBox2.Text;
            //string sql = "Select Name from Accounts WHERE Login = 'admin' AND Password='yaadmin'";
            string sql = "Select Name from Accounts WHERE Login = '"+login+"' AND Password='"+password+"'";
             MySqlCommand command = new MySqlCommand(sql, conn); 
            string name = command.ExecuteScalar().ToString(); 
            MessageBox.Show(name);
            Form2 fr2 = new Form2();
            fr2.Show();
            Hide(); 


        }
    }
}

OPTIONAL: The error occurs when creating the second form, when working with one form, the error does not occur.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LiptonOlolo, 2018-09-06
@LiptonOlolo

I advise you to look towards EntityFramework .
Show the code of the second form, there are no psychics here to guess what you have written there.

C
Chipu, 2018-09-06
@Chipu

Full error code
System.InvalidOperationException: "Initialization is not possible due to missing CategoryName."

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question