一个很简单的程序,但是不知道哪里出问题了,请指教! 我记得我一直操作DataGridView控件是这么操作的,你的意思是加一句dgvFill.DataBind();代码?这句代码要加到哪? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 dgvFill.DataSource = set.Tables["DB_NB_RangerInfo"]; dgvFill.DataBind();//有2个地方要加 我到没有用过这种用法,刚刚把这句代码添加进去以后,系统提示并不包含BataBind()的定义! BataBind()是web中的绑定数据方法 刚刚运行的时候,从登陆界面进入,提示错误:在 System.InvalidOperationException 中第一次偶然出现的“System.Data.dll”类型的异常连接未关闭。 连接的当前状态为打开。登陆界面代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;using System.Text.RegularExpressions;namespace NB_RangerDemo{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnClose_Click(object sender, EventArgs e) { Application.Exit(); } private void btnLogin_Click(object sender, EventArgs e) { try { DBHerper.connection.Open(); String sql = string.Format("select count(*) from LoginInfo where Username = '{0}' and Password = '{1}'", txtUserName.Text, txtPwd.Text); SqlCommand command = new SqlCommand(sql, DBHerper.connection); int result = Convert.ToInt32(command.ExecuteScalar()); if (result == 1) { FormFill Fills = new FormFill(); Fills.Show(); this.Visible = false; } else { MessageBox.Show("登陆失败!"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { DBHerper.connection.Close(); } } private void txtPwd_TextChanged(object sender, EventArgs e) { try { Regex r = new Regex("^[0-9]{1,}$"); if (!r.IsMatch(txtPwd.Text)) { txtPwd.Text = ""; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } private void txtUserName_TextChanged(object sender, EventArgs e) { try { Regex r = new Regex("^[0-9]{1,}$"); if (!r.IsMatch(txtUserName.Text)) { txtUserName.Text = ""; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }}会不会是这里出问题了?但是在try中: finally { DBHerper.connection.Close(); }登陆以后数据库应该为关闭状态! finally { DBHerper.connection.Close(); }是在try 和catch执行完后运行的,这里面一般就是放数据库的关闭 它是最终关闭数据库连接卅,也就是刚刚登陆进去的时候load中就开始报异常数据库未关闭, 你把 DBHerper.connection.Close();放到try最后面去看看 C#遍历远程文件夹 程序用存储过程向数据库添加数据,怎么样反回具体错误信息 winform 模拟 webform POST提交 需提交文件 抢分:正则 -----------winform 中treeView,和DataGridView的连动问题?? 一个简单的问题,回答立即给分 插入ntext的困惑(已去除16) 关于Global.asax的疑惑??? 求教客户端取request的问题!在线等!! 高分,请问在VS.NET环境中ASP.NET页面的问题 如何写如下正则表达式? 菜鸟问题 table写法
dgvFill.DataSource = set.Tables["DB_NB_RangerInfo"]; dgvFill.DataBind();//有2个地方要加
我到没有用过这种用法,
刚刚把这句代码添加进去以后,
系统提示并不包含BataBind()的定义!
在 System.InvalidOperationException 中第一次偶然出现的“System.Data.dll”类型的异常
连接未关闭。 连接的当前状态为打开。
登陆界面代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Text.RegularExpressions;namespace NB_RangerDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
} private void btnLogin_Click(object sender, EventArgs e)
{
try
{
DBHerper.connection.Open();
String sql = string.Format("select count(*) from LoginInfo where Username = '{0}' and Password = '{1}'", txtUserName.Text, txtPwd.Text);
SqlCommand command = new SqlCommand(sql, DBHerper.connection);
int result = Convert.ToInt32(command.ExecuteScalar());
if (result == 1)
{
FormFill Fills = new FormFill();
Fills.Show();
this.Visible = false;
}
else
{
MessageBox.Show("登陆失败!");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
DBHerper.connection.Close();
}
} private void txtPwd_TextChanged(object sender, EventArgs e)
{
try
{
Regex r = new Regex("^[0-9]{1,}$");
if (!r.IsMatch(txtPwd.Text))
{
txtPwd.Text = "";
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
} private void txtUserName_TextChanged(object sender, EventArgs e)
{
try
{
Regex r = new Regex("^[0-9]{1,}$");
if (!r.IsMatch(txtUserName.Text))
{
txtUserName.Text = "";
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}会不会是这里出问题了?
但是在try中:
finally
{
DBHerper.connection.Close();
}
登陆以后数据库应该为关闭状态!
{
DBHerper.connection.Close();
}
是在try 和catch执行完后运行的,这里面一般就是放数据库的关闭
也就是刚刚登陆进去的时候load中就开始报异常数据库未关闭,