romasha ali

romasha ali

  • NA
  • 94
  • 38.5k

C#

Oct 28 2013 6:28 PM
this my code which should give result like when i m enter teachername or studentname or subjectname in txtbox it will show data about that txt but it didnt show anything kindly help me out......


using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace WebApplication4
{
    public partial class Site1 : System.Web.UI.MasterPage{
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDatabase"].ToString());

        protected void Page_Load(object sender, EventArgs e)
        {
            con.Open();
          

        }

      
        protected void Button1_Click1(object sender, EventArgs e)
        {

            //string intero = "Select * from [All Tables] where [Teacher Name]='" + Txt.Text + "' || [Student Name]='" + Txt.Text + "' || [Subject Name] = '" + Txt.Text + "'";

            //SqlCommand cmd = new SqlCommand(intero, con);

            SqlParameter sql = new SqlParameter("@TeacherName", Txt.Text.Trim());
            SqlParameter sql1 = new SqlParameter("@StudentName", Txt.Text.Trim());
            SqlParameter sql2 = new SqlParameter("@SubjectName", Txt.Text.Trim());
            SqlCommand cmd = new SqlCommand("db", con);
            cmd.Parameters.Add(sql);
            cmd.Parameters.Add(sql1);
            cmd.Parameters.Add(sql2);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            SqlDataReader dr = cmd.ExecuteReader();
//
           // SqlDataReader rdr;

           // rdr = cmd.ExecuteReader();

           
            while (dr.Read())
            {


                Lbl1.Text += dr[0] + "" + dr[1] + "" + dr[2] + "" + dr[3] + "<br/>";
                Lbl1.Visible = true;
            }

          
            //while (rdr.Read())
            //{

            //    if (rdr[1].Equals(Txt.Text))
            //    {
            //        Lbl1.Text += rdr[0] + "" + rdr[1] + "" +rdr[3] + "" + rdr[4]+ "<br/>";
                    dr.Close();
                    con.Close();
                   
                }
            }


}
this is my Stored procedure:

ALTER PROCEDURE db(@TeacherName varchar(MAX),@StudentName Varchar(MAX),@SubjectName Varchar(MAX))
   
AS  Select * from Faculty,Student,Subject where TeacherName=@TeacherName OR StudentName=@StudentName OR SubjectName=@SubjectName

    /* SET NOCOUNT ON */
    RETURN

Answers (6)