Step 1 : Create Function
private void FillSubjects()
{
DataSet ds = new DataSet();
ds = FillSubject();
if (ds.Tables[0].Rows.Count > 0)
{
ddlsplsub.DataTextField = "SubjectName";
ddlsplsub.DataValueField = "SubjectId";
ddlsplsub.DataSource = ds;
ddlsplsub.DataBind();
}
}
public DataSet FillSubject()
{
ds = new DataSet();
try
{
ds = GetSubject(); //12/11/2013
if (ds.Tables[0].Rows.Count > 0)
{
DataRow dr = ds.Tables[0].NewRow();
dr["SubjectId"] = "0";
dr["SubjectName"] = "Select Subject";
ds.Tables[0].Rows.InsertAt(dr, 0);
}
}
catch (Exception ex)
{
ds = null;
}
return ds;
}
public DataSet GetSubject()
{
strQuery = "select SubjectId,rtrim(SubjectName) as SubjectName from SubjectsMaster order by subjectName asc";
using (SqlCommand cmd = GetCommand(strQuery, CommandType.Text))
{
ds = new DataSet();
SqlDataAdapter SqlAdp = new SqlDataAdapter(cmd);
SqlAdp.Fill(ds);
DBhelper.Instance.CloseConnection(cmd);
}
return ds;
}
public SqlCommand GetCommand(string spName, CommandType CommandType)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = spName;
cmd.CommandType = CommandType;
cmd.Connection = ConnectionString;
return cmd;
}
public SqlConnection ConnectionString
{
get
{
_connectionString = new SqlConnection(Getconnect());
_connectionString.Open();
return _connectionString;
}
}
public string Getconnect()
{
string connectionsring = ConfigurationManager.ConnectionStrings["Elearning"].ConnectionString;
return connectionsring;
}
private void FillSubjects()
{
DataSet ds = new DataSet();
ds = FillSubject();
if (ds.Tables[0].Rows.Count > 0)
{
ddlsplsub.DataTextField = "SubjectName";
ddlsplsub.DataValueField = "SubjectId";
ddlsplsub.DataSource = ds;
ddlsplsub.DataBind();
}
}
public DataSet FillSubject()
{
ds = new DataSet();
try
{
ds = GetSubject(); //12/11/2013
if (ds.Tables[0].Rows.Count > 0)
{
DataRow dr = ds.Tables[0].NewRow();
dr["SubjectId"] = "0";
dr["SubjectName"] = "Select Subject";
ds.Tables[0].Rows.InsertAt(dr, 0);
}
}
catch (Exception ex)
{
ds = null;
}
return ds;
}
public DataSet GetSubject()
{
strQuery = "select SubjectId,rtrim(SubjectName) as SubjectName from SubjectsMaster order by subjectName asc";
using (SqlCommand cmd = GetCommand(strQuery, CommandType.Text))
{
ds = new DataSet();
SqlDataAdapter SqlAdp = new SqlDataAdapter(cmd);
SqlAdp.Fill(ds);
DBhelper.Instance.CloseConnection(cmd);
}
return ds;
}
public SqlCommand GetCommand(string spName, CommandType CommandType)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = spName;
cmd.CommandType = CommandType;
cmd.Connection = ConnectionString;
return cmd;
}
public SqlConnection ConnectionString
{
get
{
_connectionString = new SqlConnection(Getconnect());
_connectionString.Open();
return _connectionString;
}
}
public string Getconnect()
{
string connectionsring = ConfigurationManager.ConnectionStrings["Elearning"].ConnectionString;
return connectionsring;
}
No comments:
Post a Comment