textbox1中输入内容,当textbox1失去焦点时,查询数据库中是否有与textbox1查询条件中相同的内容,若无给出提示信息,若有,则将其他字段分别显示在其他textbox中(每个textbox显示一个字段的内容)

解决方案 »

  1.   

    可以在TextChanged加入查詢代碼
    如果要無刷新就用AJAX
      

  2.   

    private   void   textBox1_Leave(object   sender,   System.EventArgs   e)   
      {   
              if(!string.isNullOrEmpty(textBox1.Text))
              {
               string sql="select * from tablename where filedname='"+textBox1.Text+"' "; 
               ..执行查询
                if(有值)
              {
                    MessageBox.Show("该值已经存在!");
              }
              }
              
    }
      

  3.   

    主要在Leave事件中编写。
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication6
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void textBox1_Leave(object sender, EventArgs e)
            {
                string str = @"数据库连接字符串";
                SqlConnection conn = new SqlConnection(str);
                SqlCommand cmd = new SqlCommand("select * from 表名 where 字段名 =" + textBox1.Text.Trim(), conn);
                DataSet ds=new DataSet();
                SqlDataAdapter da=new SqlDataAdapter(cmd);
                conn.Open();
                da.Fill(ds,"表名");
                DataTable dt=ds.Tables["上一行中的表名"];
                textBox2.Text = dt.Rows[0][1].ToString();
            }
        }
    }
      

  4.   

    private void textBox1_Leave(object sender, EventArgs e) 
            { 
                string str = @"数据库连接字符串"; 
                SqlConnection conn = new SqlConnection(str); 
                SqlCommand cmd = new SqlCommand("select * from 表名 where 字段名 =" + textBox1.Text.Trim(), conn); 
                DataSet ds=new DataSet(); 
                SqlDataAdapter da=new SqlDataAdapter(cmd); 
                conn.Open(); 
                da.Fill(ds,"表名"); 
                DataTable dt=ds.Tables["上一行中的表名"]; 
                textBox2.Text = dt.Rows[0][1].ToString(); 
            } 
    使用如下代码后
    好象我在运行程序的时候好象没有执行这个代码呢!!!!
    我在textBox1_Leave代码中加入了一句textBox1.Enabled = false;
    当光标离开textbox1的时候 textbox1都没有反应呢~~~~