Hi,
I have a gridview which display the list of student details from the database. I have used webservice in this. what is the problem here is, when i add this web service to the application the data of student is not fetched from the database , but it worked wel when i tried before adding the webservice. I dono what is the problem, Please help me to find out.
DAL:
public class StudentDALClass
{
string constring = System.Configuration.ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
///
/// Binding the Gridview
///
///
public DataTable StudentGridBindDAL()
{
SqlConnection con = new SqlConnection(constring); ;
DataTable dt = new DataTable();
SqlDataAdapter dataAdapter;
SqlCommandBuilder commandBuilder;
try
{
con.Open();
dataAdapter = new SqlDataAdapter("spSelectStudentTable", con);
commandBuilder = new SqlCommandBuilder(dataAdapter);
dataAdapter.Fill(dt);
return dt;
}
catch (SqlException)
{
throw new Exception("Error Occurred in DB, Please try again later");
}
catch (NullReferenceException)
{
throw new Exception("Invalid data has been passed");
}
catch (FormatException)
{
throw new Exception("Iput string was not in a correct formate");
}
catch (IndexOutOfRangeException)
{
throw new Exception("Invaid input has been passed");
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}
}
BLL:
public class StudentBLLClass
{
StudentDALClass dal = new StudentDALClass();
///
/// binding the student data to the grid view
///
///
public DataTable StudnetBindBLL()
{
DataTable dt;
try
{
dt = dal.StudentGridBindDAL();
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
} WEB Service :
[ServiceContract]
public interface IService1
{
[OperationContract]
DataTable StudnetBindService();
[OperationContract]
void AddStudentService(StudentEntityClass se);
[OperationContract]
void UpdateStudentService(StudentEntityClass se);
[OperationContract]
void DaleteStudentService(StudentEntityClass se);
}
//implementing interface
public class Service1 : IService1
{
StudentBLLClass bll = new StudentBLLClass();
public DataTable StudnetBindService()
{
DataTable dt;
dt = bll.StudnetBindBLL();
return dt;
}
public void AddStudentService(StudentEntityClass se)
{
bll.AddStudentBLL(se);
}
public void UpdateStudentService(StudentEntityClass se)
{
bll.UpdateStudentBLL(se);
}
public void DaleteStudentService(StudentEntityClass se)
{
bll.DaleteStudentBLL(se);
}
}
Code Behind: StudentBLLClass bll = new StudentBLLClass();
StudentListServiceReference.Service1Client servicereference = new StudentListServiceReference.Service1Client();
///
/// Displaying gridview in pageload
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
try
{
GridBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
EntityLayer:
public class StudentEntityClass
{
public int StudentId { get; set; }
public string StudentName { get; set; }
public string EmailId { get; set; }
public string PhoneNumber { get; set; }
public string City { get; set; }
} UI Layer:
List Of Students
DataKeyNames="StudentID" ShowFooter="true" CellPadding="4" ForeColor="#333333" GridLines="None"
HorizontalAlign="Center" OnRowCancelingEdit="grdStudentList_RowCancelingEdit" OnRowEditing="grdStudentList_RowEditing"
OnRowUpdating="grdStudentList_RowUpdating" OnRowDeleting="grdStudentList_RowDeleting">
WEB CONFIG FILE:
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naveen KumarPosted Oct 26, 2017, 10:48 AM
Monica PriyadharshiniPosted Oct 26, 2017, 9:10 AM
Naveen KumarPosted Oct 26, 2017, 8:10 AM