错误 3 当前上下文中不存在名称“conn”

qq_26336939 2016-01-29 01:24:15
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ConsoleApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection (
"Data Source=.;Initial Catalog=hospitalms;User ID Security==sa;Password=123456"));
{
conn.Open();
}
}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}
...全文
162 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdnFUCKINGSUCKS 2016-01-29
  • 打赏
  • 举报
回复
using的最后多了个分号,结束了using的代码块,再在下面的代码里访问conn当然是访问不到的。 话说你的IDE连这么基本的语法错误都不能即时显示吗?

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧