Tuesday, February 2, 2010

Displaying the data in GridView

string constr = ConfigurationManager.ConnectionStrings["Reports"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("Matrix", con);

SqlDataAdapter adap = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();

try
{

cmd.CommandType = CommandType.StoredProcedure;

CultureInfo ci = new CultureInfo("en-US");
cmd.Parameters.Add("@StartDate", SqlDbType.VarChar).Value = DateTime.Parse(txtProjectStartDt.Text, new CultureInfo("en-GB")).ToString("d", new CultureInfo("en-US"));
cmd.Parameters.Add("@Enddate", SqlDbType.VarChar).Value = DateTime.Parse(txtProjectEndDt.Text, new CultureInfo("en-GB")).ToString("d", new CultureInfo("en-US"));

adap.Fill(ds, "Orders");

if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
gvCrossTab.DataSource = ds.Tables[0];
gvCrossTab.PageSize =10;
gvCrossTab.DataBind();
}
else
{
Response.Write("No Record Exist");
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();

con = null;
}

No comments:

Post a Comment