为什么显示当前上下文中不存在名称"Conn"
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("请输入要连接的数据库名称");
}
else
{
try
{
string ConStr = "sever=.;database=" + textBox1.Text.Trim() + ";uid=sa;pwd=sasa";
SqlConnection conn = new SqlConnection(ConStr);
Conn.Open();
if (conn.State == ConnectionState.Open)
{
label1.Text = "数据库[" + textBox1.Text.Trim() + "]已经连接并打开";
}
}
catch
{
MessageBox.Show("连接数据库失败");
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}