Click here to Skip to main content
15,512,747 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to get record based on it's Rollnumber suppose if i enter the Rollnumber in textbox the details of the Record should display on Respective textboxes
i have tried ito and written the following code but not working how to get it?
Make some changes to my code where i did wrong.

In data access layer

public DataSet FindRecord(int RollNumber)
{
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("spfindtblstudent", con);
cmd.Parameters.AddWithValue("@RollNumber", RollNumber);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter("cmd", con);
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
return ds;


}
}

in BusinessLogicLayer

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


In Code behind File

C#
protected void btnfind_Click(object sender, EventArgs e)
        {

            Bo objbo = new Bo();
            objbo.Name = txtname.Text.ToString();
            objbo.Address = txtaddress.Text.ToString();
            objbo.Phone = txtphone.Text.ToString();



        }




Regards
Posted
Updated 1-Nov-14 0:01am
v3
Comments
Laiju k 1-Nov-14 5:04am    
where are you calling findRec(int RollNumber)
raxhemanth 1-Nov-14 5:07am    
yes in businesslogiclayer
raxhemanth 1-Nov-14 5:12am    
protected void btnfind_Click(object sender, EventArgs e)
{

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


}

Do u want me to write like this is this write but
objbll.findRec(RollNumber);
Here the method is saying that RollNumber Doesnot exist in the correct Context.
What does it mean
Laiju k 1-Nov-14 5:15am    
use reply option when repling
raxhemanth 1-Nov-14 5:14am    
Try to help me iam new to 3-Tier
Thanks in advance

method public DataSet FindRecord(int RollNumber) is return data set, so you can get the result after you call that method in your BusinessLogicLayer

C#
public void findRec(int RollNumber)
      {
          Dal objdal = new Dal();
          DataSet ds = objdal.FindRecord(RollNumber);
          // ds.Tables[0] will have  the data you need 
      }


you can return this data set by changing signature of the method as below

C#
public DataSet findRec(int RollNumber)
      {
          Dal objdal = new Dal();
          DataSet ds = objdal.FindRecord(RollNumber);
          return ds; 
      }


then

C#
protected void btnfind_Click(object sender, EventArgs e)
        {
            int rollnumber = int.Parse(txtrollnumber.Text);
            Bo objbo = new Bo();
            DataSet ds =objbo.findRec(rollnumber);
            if(ds !=null && ds.Tables.Count >0 && ds.Tables[0].Rows.Count >0)
            {
                txtName.Text = ds.Tables[0].Rows[0]["Name"].ToString();
                txtAddress.Text = ds.Tables[0].Rows[0]["Address"].ToString();
                txtPhone.Text = ds.Tables[0].Rows[0]["Phone"].ToString();
            }
        }
 
Share this answer
 
v2
Comments
raxhemanth 1-Nov-14 5:16am    
Great Tankyou very much DamithSL
Laiju k 1-Nov-14 5:21am    
raxhemanth
Accept the Solution as Answer if it solved your problem
Laiju k 1-Nov-14 5:20am    
DamithSL,
1)can you tell me why you are using this condition

if(ds !=null && ds.Tables.Count >0 && ds.Tables[0].Rows.Count >0)

and

2)if we know it returns only one cant we use DataTable instead of DataSet
DamithSL 1-Nov-14 5:24am    
1. if there is no records, you will get exception when you assign values for the text boxes, that's why I have added few validations
2. yes, you can return Datatable, or even object like Student, create class with few properties like name, address etc. and you can return object of that class after setting properties with help of returned values from database

hope this helps
Laiju k 1-Nov-14 5:25am    
Thanks
C#
public DataSet FindRecord(int RollNumber)
{
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("spfindtblstudent", con);
cmd.Parameters.AddWithValue("@RollNumber", SqlDbType.BigInt).Value = RollNumber;
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
 
Share this answer
 
Comments
raxhemanth 1-Nov-14 5:45am    
oh Thankyou Somuch kskumaran
raxhemanth 1-Nov-14 6:04am    
what code i need to write in code behind please tell me
kskumaran 1-Nov-14 6:37am    
what code means?

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