【发布时间】:2017-12-16 12:46:33
【问题描述】:
我想连接到我的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();
}
【问题讨论】:
-
您是在说,实际上是在调用
NullReferenceException时抛出Open? -
是的,我打电话,问题解决了。非常感谢:)
标签: c# sql .net sql-server ado.net