C#连接数据库问题
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace WindowsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() == "")
{
MessageBox.Show("姓名不能为空");
return;
}
SqlConnection cmd = new SqlConnection("server=(local);User ID=sa;pwd=;Database=zhonhouse");
cmd.Open();
SqlCommand cnd = new SqlCommand("select*from login ");
= "select count(*) from login where login_name=" + textBox1.Text + " and login_pwd=" + textBox2.Text + "";
Int32 count = (Int32)cnd.ExecuteScalar();
if (count > 0) MessageBox.Show("ok");
}
}
}
启动后为什么会出现ExecuteScalar: Connection 属性尚未初始化。