我总是犯这个错误

我总是犯这个错误

本文介绍了我总是犯这个错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Web.Security;

public partial class Admin_uyeekle : System.Web.UI.Page
{
    string baglantistringi = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
       HttpContext.Current.Server.MapPath("~/App_Data/VT.accdb") +
       ";Persist Security info=false";
    OleDbConnection Baglanti;
    OleDbDataAdapter Adaptor;
    DataTable qwe;
    OleDbCommand ab;
    public static int IDKullanici;
  
    protected void cusval1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        string cevap =" 16";
        string kulcevabı = args.Value;
        if(cevap!=kulcevabı)
        {
            args.IsValid = false;
        }
    }
    protected void btn_kaydet_Click(object sender, EventArgs e)
    {
        string isim = txt_ad.Text;
        string soyisim = txt_soyad.Text;
        string Email = txt_email.Text;
        string Sifre = txt_sifre.Text;
        string SifreTekrar = txt_sifretekrar.Text;
        string kayitekle;

        if (KullaniciEmailKontrolEt() != 0)
        {
            lbl_uyari.Visible = true;
            lbl_uyari.Text = "ayni email adresi ile kayıt yapılmıştır.";
            return;
        }
        kayitekle = "INSERT into Kullanicilar(isim,soyisim,mail,sifre,kullanicitipi) Values(@isim,@soyisim,@mail,@sifre,@kullanicitipi)";


        ab = new OleDbCommand(kayitekle, Baglanti);
        ab.Parameters.Add("@isim", OleDbType.Char, 100).Value = isim;
        ab.Parameters.Add("@soyisim", OleDbType.Char, 100).Value = isim;
        ab.Parameters.Add("@mail", OleDbType.Char, 100).Value = Email;
        ab.Parameters.Add("@sifre", OleDbType.Char, 50).Value = Sifre;
        ab.Parameters.Add("@kullanicitipi", OleDbType.Char, 50).Value = "UYE";
        try
        {
            Baglanti.Open();
            ab.ExecuteNonQuery();
            Baglanti.Close();
            lbl_uyari.Text = "Kayıt Başarılı";
        }
        catch (Exception hata)
        {
            lbl_uyari.Text = "Kayıt yapılamadı";
        }
    }
    public int KullaniciEmailKontrolEt()
    {
        DataTable dataEmailKontrol = new DataTable();
        string abc = "Select mail From uye Where mail=@mail";
        OleDbCommand ab = new OleDbCommand(abc, Baglanti);
        ab.Parameters.Add("@mail", OleDbType.Char, 50).Value = txt_email.Text;
        Adaptor = new OleDbDataAdapter(ab);
        if (Baglanti.State == ConnectionState.Closed)
        {
            Baglanti.Open();
        }
        
        Adaptor.Fill(dataEmailKontrol);
        if (Baglanti.State == ConnectionState.Open)
        {
            Baglanti.Close();
        }
        return dataEmailKontrol.Rows.Count;
    }
    
  
    
}







system.NullReferenceException




system.NullReferenceException

推荐答案


OleDbConnection Baglanti;
ab = new OleDbCommand(kayitekle, Baglanti);
Baglanti.Open();
Baglanti.Close();
OleDbCommand ab = new OleDbCommand(abc, Baglanti);
if (Baglanti.State == ConnectionState.Closed)
Baglanti.Open();
if (Baglanti.State == ConnectionState.Open)
Baglanti.Close();



你实际上从来没有给它赋值......在某个地方,你需要添加


You never actually assign a value to it...somewhere, you need to add

Baglanti = new OleDbConnection(baglantistringi);


这篇关于我总是犯这个错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 07:52