日期:2014-05-17  浏览次数:20623 次

在VS2010实现模糊查询(LIKE格式)的问题
            string temp = txt姓名查找.Text;

            string ConStr = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(ConStr))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText =@"Select *from T_Person where Name LIKE '%:temp%'";
                    using (SqlDataReader read=cmd.ExecuteReader())
                    {
                        while(read.Read())
                        {
                           if (lbx模糊显示.Text == "")
                          {
                            lbx模糊显示.Text = Convert.ToString(read.GetOrdinal("Name")) ;
                          }
                          else
                         {
                            lbx模糊显示.Text = lbx模糊显示.Text + Convert.ToString(read.GetOrdinal("Name")) ; 
                          }
                        }
                         MessageBox.Show(Convert.ToString(read.GetOrdinal("Name")));
                    }