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

为什么只能返回数据库中的一条记录,其它的都显示不出来!
 private void button5_Click(object sender, EventArgs e)
        {
            string cstr = @"Data Source=.;Initial Catalog=student;Integrated Security=True";
            string sql = "select * from Score where sno=@SNO";
            StringBuilder str = new StringBuilder();
            using (SqlConnection conn = new SqlConnection(cstr))
            {
                using (SqlCommand cmd = new SqlCommand(sql, conn))
                {
                    conn.Open();
                    cmd.Parameters.Add(new SqlParameter("SNO", textBox1.Text));
                    using (SqlDataReader rd = cmd.ExecuteReader())
                    {
                        if (rd.Read())
                        {
                            str.Append(textBox1.Text);
                            str.Append('|');
                            str.Append(rd.GetString(1));
                            str.Append('|');
                            str.Append(float.Parse(rd.GetValue(2).ToString()).ToString());
                            str.Append("\r\n");
                        }
                    }
                }
            }
            textBox2.Text = str.ToString();
   &nb