我的搜索按钮不显示数据

本文关键字:显示 数据 按钮 搜索 我的 | 更新日期: 2023-09-27 18:37:06

>我使用VS2010为诊所构建窗口表单应用程序。在表单上有一个搜索按钮,显示基于注册号的数据库。
当我测试应用程序时,提供注册号并单击搜索
按钮不显示任何内容,也不显示错误消息。
这是我的代码

        string connectionstring = "Data Source=localhost;Initial Catalog=HMS;Persist Security Info=True;User ID=Developer;Password=abc@123";
        SqlConnection connection = new SqlConnection(connectionstring);
        string SelectStatement = "SELECT * FROM MyTable where RegistrationNo = '@RegistraionNo'";
        SqlCommand insertcommand = new SqlCommand(SelectStatement, connection);
        insertcommand.Parameters.AddWithValue("@RegistrationNo", txtsearch.Text);
        SqlDataReader reader;
        try
        {
            connection.Open();
            reader = insertcommand.ExecuteReader();
            while (reader.Read())
            {
                textBox3.Text = reader["RegistratioNo"].ToString();
                textBox1.Text = reader["FirstName"].ToString();
                textBox2.Text = reader["LastName"].ToString();
                genderOption.Text = reader["Sex"].ToString();
                textBox7.Text = reader["Contact"].ToString();
                textBox4.Text = reader["Age"].ToString();
                textBox5.Text = reader["Weight"].ToString();
                textBox6.Text = reader["Weight"].ToString();
                comboBox1.Text = reader["Tribe"].ToString();
            }//end while
            reader.Close();
        }
        catch (SqlException ex)
        {
            throw ex;
        }//end catch
        finally
        {
            connection.Close();
        }// end finally

'

我的搜索按钮不显示数据

你有错别字

注册号而不是注册号

string SelectStatement = "SELECT * FROM MyTable where RegistrationNo = '@RegistraionNo'";

另一个在

textBox3.Text = reader["RegistratioNo"].ToString();

您将复制 100 行

我想要一个注册,我想要一个注册

,我想要一个注册。