| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 707 人关注过本帖
标题:为什么显示当前上下文中不存在名称"Conn"
取消只看楼主 加入收藏
byp2011
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-6-7
结帖率:0
收藏
 问题点数:0 回复次数:0 
为什么显示当前上下文中不存在名称"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)
        {

        }

    }
}
搜索更多相关主题的帖子: void private public 上下文 
2012-07-09 15:02
快速回复:为什么显示当前上下文中不存在名称"Conn"
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017569 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved