Wednesday, July 28, 2010

ADO.NET Entity Framework

Create a EDM by adding a new ADO.NET Entity Data Model. Add your Database to it...

Some terms used.....
EDM - Entity Data Model (Mapping Layer)
CSDL - Conceptual Schema Definition Language (Conceptual Layer)
SSDL - Stored Schema Definition Language (Logical Layer)

Extension .edmx

Codes after creating the EDM file....

NationalBankModel.NationalBankEntities mm = new NationalBankModel.NationalBankEntities();
//var query = from n in mm.EmployeeDetails
// select n;


//var query = from n in mm.EmployeeDetails
// where mm.Logins.Any(Emp => Emp.EmpID >3)
// select new {n.EmpID, n.EmpName, n.EmpAddress, n.EmpPhNo };

var query = from n in mm.EmployeeDetails
//join oo in mm.Logins on n.EmpID equals oo.EmpID
where mm.Logins.Any(Emp => Emp.EmpID == 3)
//where n.EmpID > 2
select new { n.EmpID, n.EmpName, n.EmpAddress, n.EmpPhNo };

GridView1.DataSource = query;
GridView1.DataBind();

foreach (var emp in mm.EmployeeDetails)
{
ListItem li = new ListItem();
li.Text = emp.EmpID + " ";
if (!emp.Logins.IsLoaded)
{
emp.Logins.Load();
}

foreach (var p in emp.Logins)
{
li.Text += "Login Name: " + p.username + " ";
}

BulletedList1.Items.Add(li);
}

Monday, July 26, 2010

Custom Reporting using Crystalreports

Namespaces to use.

using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;

Code....
SqlConnection con=new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=NationalBank;Integrated Security=True");
SqlDataAdapter da=new SqlDataAdapter("select * from EmployeeDetails where EMpname like 'g%'",con);

DataSet ds = new DataSet();
da.Fill(ds, "d");


ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath(@"~\CrystalReport.rpt"));
rpt.SetDataSource(ds.Tables["d"]);
CrystalReportViewer1.ReportSource = rpt;

Thursday, July 15, 2010

Taking index of a row in Gridview using RowCommand

For taking data using rowcommand property....

When you create the code of Gridview place the code like this for your customized Controls(Button)


<asp:imagebutton id="imgProfile" width="100px" height="100px" runat="server" imageurl="'<%#">' CommandName="cmdImage" CommandArgument='<%# Container.DataItemIndex %>' />
Here look at the COmmand argument property it should be like this. Then only we can take the Index of the Gridview.

Now, in Code behind you can call it like this....

string name = ((TextBox)GridView1.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("TextBoxName")).Text;

thus you can work on it getting the index of the row.

Fetch data from Footer of Gridview

Taking data from the Footer of a Gridview control in asp.net

GridViewRow row = GridView1.FooterRow;
if (e.CommandName == "cmdSUBMIT")
{
string name = ((TextBox)row.FindControl("TextBoxName")).Text;
Response.Write(name);
}