Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
code in Data Access Layer

C#
public void FindRecord(int RollNumber)
       {
           using (SqlConnection con = new SqlConnection(cs))
           {
               using(SqlCommand cmd = new SqlCommand("spfindtblstudent",con))
               {
                   cmd.Parameters.Add("@RollNumber", RollNumber);
                   cmd.CommandType = CommandType.StoredProcedure;
                   con.Open();
                   cmd.ExecuteNonQuery();
               }
           }
       }


Code in Business Logic

C#
public void find(int RollNumber)
      {
          Dal objdal = new Dal();
          objdal.FindRecord(RollNumber);
      }


Code in code behind

protected void btnfind_Click(object sender, EventArgs e)
{

Bo objbo = new Bo();
objbo.Name = txtname.Text;
objbo.Address = txtaddress.Text;
objbo.Phone = txtphone.Text;
Bll objbll = new Bll();
objbll.find(RollNumber);


}

Not Working At all

Iam new to 3-Tier but trying to find the record what is thec code have to write and does my code make any sense
Please
Help me out
thanks in advance
Posted
Updated 31-Oct-14 20:32pm
v2
Comments
Robert Welliever 1-Nov-14 2:35am    
If you are trying to find a record then you should execute a query instead of executing a non-query. What is your proc "spfindtblstudent" doing instead of selecting the record?

1 solution

ExecuteNonQuery is not return the results of sql statement which executed, you can use DataReader[^] or DataAdapter[^] to get DataSet or DataTable result. Read the documentation and check the samples in the MSDN for more information.
after you get DataTable or DataSet you can return that object from FindRecord method by changing the signature as below
C#
public DataTable FindRecord(int RollNumber)
{

      // retrieve data from database
      //finally return datatable; 
}

Then you can get the data table as below
C#
Dal objdal = new Dal();
DataTable dt= objdal.FindRecord(RollNumber);

sample code:
C#
public DataTable FindRecord(int RollNumber)
{
    using(SqlConnection sqlConn = new SqlConnection(cs))
    using(SqlCommand cmd = new SqlCommand("spfindtblstudent", sqlConn))
    {
        cmd.Parameters.Add("@RollNumber", RollNumber);
        cmd.CommandType = CommandType.StoredProcedure;
        sqlConn.Open();
        DataTable dt = new DataTable();
        dt.Load(cmd.ExecuteReader());
        return dt;
    }
}


I assume that your stored procedure having select statement which return matching data.
 
Share this answer
 
v3
Comments
raxhemanth 1-Nov-14 2:38am    
Thanks DamithSL thankyousomuch
DamithSL 1-Nov-14 3:23am    
You are welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900