System.NullReferenceException: 'Nesne başvurusu bir nesnenin örneğine ayarlanmadı.'
con, null idi.
Programı çalıştırırken yukarıda yazan hatayı almaktayım. Aşağı tarafta yazdığım kodu görebilirsiniz.
private **** NewMethod1()
{
con.Open();
}
}
Çalıştırınca bu kısımda hata vermektedir. System.NullReferenceException: 'Nesne başvurusu bir nesnenin örneğine ayarlanmadı.'
con, null idi. diyerek hata alıyorum. Konuyla ilgili yardımcı olabilecek arkadaşlar olursa sevinirim.
con, null idi.
Programı çalıştırırken yukarıda yazan hatayı almaktayım. Aşağı tarafta yazdığım kodu görebilirsiniz.
private **** NewMethod1()
{
con.Open();
}
}
Çalıştırınca bu kısımda hata vermektedir. System.NullReferenceException: 'Nesne başvurusu bir nesnenin örneğine ayarlanmadı.'
con, null idi. diyerek hata alıyorum. Konuyla ilgili yardımcı olabilecek arkadaşlar olursa sevinirim.
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 projedeneme
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SQLiteConnection con;
SQLiteDataAdapter da;
SQLiteCommand cmd;
DataSet ds;
SQLiteDataReader dr;
**** GetList()
{
NewMethod();
da = new SQLiteDataAdapter("Select *From user", con);
ds = new DataSet();
con.Open();
da.Fill(ds, "user");
con.Close();
}
private **** NewMethod()
{
con = new SQLiteConnection("Data Source=mustafa.db3;Version=3;");
}
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 **** 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 + "'";
dr = cmd.ExecuteReader();
if (dr.Read())
{
Form2 f2 = new Form2();
f2.Show();
}
else
{
MessageBox.Show("Kullanıcı adı ya da şifre yanlış");
}
con.Close();
GetList();
}
private **** NewMethod1()
{
con.Open();
}
}
}