小编Dlk*_*nng的帖子

SqlConnection为null但为什么?

我想连接到我的GuvenliBilgisayarim数据库.但是baglanti为空 - 为什么?

我的代码是:

SqlConnection baglanti = new SqlConnection("Data Source=DILEKZ\\SQLEXPRESS;Initial Catalog=GuvenliBilgisayarim;Integrated Security=True");

private void btn_giris_Click(object sender, EventArgs e)
{
    baglanti.Open();
    SqlCommand komut = new SqlCommand("select * from Login where kullanici_adi='" + txt_kulAdi.Text + " and kullanici_sifre=" + txt_sifre.Text +"',baglanti");
    komut.Connection = baglanti;

    SqlDataReader dr = komut.ExecuteReader();

    if (dr.Read())
    {
        Rapor rpr = new Rapor();
        rpr.Show();
    }
    else
    {
        MessageBox.Show("Kullan?c? ad? veya ?ifre yanl??");
    }

    dr.Close();
}
Run Code Online (Sandbox Code Playgroud)

.net c# sql sql-server ado.net

2
推荐指数
1
解决办法
153
查看次数

标签 统计

.net ×1

ado.net ×1

c# ×1

sql ×1

sql-server ×1