我记得我一直操作DataGridView控件是这么操作的,
你的意思是加一句dgvFill.DataBind();代码?
这句代码要加到哪?

解决方案 »

  1.   


    dgvFill.DataSource = set.Tables["DB_NB_RangerInfo"]; dgvFill.DataBind();//有2个地方要加
      

  2.   


    我到没有用过这种用法,
    刚刚把这句代码添加进去以后,
    系统提示并不包含BataBind()的定义!
      

  3.   

    BataBind()是web中的绑定数据方法
      

  4.   

    刚刚运行的时候,从登陆界面进入,提示错误:
    在 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();
                }
    登陆以后数据库应该为关闭状态!
      

  5.   

     finally
      {
      DBHerper.connection.Close();
      }
    是在try 和catch执行完后运行的,这里面一般就是放数据库的关闭
      

  6.   

    它是最终关闭数据库连接卅,
    也就是刚刚登陆进去的时候load中就开始报异常数据库未关闭,
      

  7.   

    你把 DBHerper.connection.Close();放到try最后面去看看