Aşağıdaki kodu debug yaptığımız zaman
System.InvalidOperationException: 'No connection associated with this command' diyor. private void NewMethod2() => dr = cmd.ExecuteReader();bu komut üzerinde kaldığını göstermektedir. Konuyla ilgili olacak yardımcı olacaak bir arkadaş olursa sevinrim
Kodların tümü
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using Microsoft.Data.Sqlite;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ![sqlitedeneme](![src](![src](src)))
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void NewMethod()
{
con = new SQLiteConnection("Data Source=mustafa.db3;Version=3;");
con.Open();
}
SQLiteConnection con;
SQLiteDataAdapter da;
SQLiteCommand cmd;
DataSet ds;
SQLiteDataReader dr;
public Form1(IContainer components, PictureBox pictureBox1, TextBox textBox1, TextBox textBox2, Label label1, Label label2, Button button1, SQLiteConnection con, SQLiteDataAdapter da, SQLiteCommand cmd, DataSet ds, SQLiteDataReader dr)
{
this.components = components;
this.pictureBox1 = pictureBox1;
this.textBox1 = textBox1;
this.textBox2 = textBox2;
this.label1 = label1;
this.label2 = label2;
this.button1 = button1;
this.con = con;
this.da = da;
this.cmd = cmd;
this.ds = ds;
this.dr = dr;
}
private void button1_Click(object sender, EventArgs e)
{
cmd = new SQLiteCommand();
NewMethod1();
cmd.Connection = con;
con = new SQLiteConnection("Data Source=mustafa.db3;Version=3;");
cmd.CommandText = "SELECT * FROM user where username='" + textBox1.Text + "' AND password='" + textBox2.Text + "'";
NewMethod2();
if (NewMethod3().Read())
{
Form2 f2 = new Form2();
f2.Show();
}
else
{
MessageBox.Show("Kullanıcı adı ya da şifre yanlış");
}
con.Close();
}
private SQLiteDataReader NewMethod3()
{
return GetDr();
}
private SQLiteDataReader GetDr()
{
return dr;
}
private void NewMethod2() => dr = cmd.ExecuteReader();
}
}