在C#窗体程序中,如何用文本框输入的条件筛选数据库的数据

if (textBox1.Text.Trim().Length != 4)
{
MessageBox.Show("請輸入完整的搜索條件", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

        }
        SqlConnection conn=new SqlConnection ("server=xxxx;UID=xx;PASSWORD=xxx;DATABASE=xxx");
        SqlCommand cmd = new SqlCommand();
        conn.Open();
        SqlDataAdapter sda = new SqlDataAdapter("sp_QueryM", conn);
    //  cmd.CommandText = "sp_QueryM";
        cmd.CommandType = CommandType.StoredProcedure;


       sda.SelectCommand.Parameters.Add("@cpm",textbox1.text.trim() );

      //  sda.SelectCommand.Parameters.Add(textBox1.Text.Trim(), "@cpm");
       // string sql = " execute sp_QueryM, '" + textBox1.Text.Trim() + "'";
      // cmd.Parameters[0].Value = "ABC";    // 暫且不用存儲過程來實現數據 的查詢

        cmd.Connection = conn;

        DataSet ds = new DataSet();

        sda.Fill(ds,"ThisYueJie");
        int i = ds.Tables[0].Rows.Count;
        if (i == 0)
        {
            MessageBox.Show("未查詢到數據!");
            return;
        }
        dgv1.DataSource = ds.Tables[0];

        conn.Close();
                    这用写会提示程序或函数没有值

这个要看sp_QueryM这个存储过程你怎么写的