After that use this tbl instance to add data to the properties,
Example:
tbl_Vender tbl = new tbl_Vender();
tbl.VenderName = "Kumar";
tbl.VenderContact = 656789
When we have provided values to the properties to the
table object, its time to save this into database for this,
Do,
db.tbl_Vender.AddObject(tbl);
Here, db is our entity object in which we have tbl_vendor
(our table). The “AddObject”(or Add, depending upon your version) is the method
provided by the entity to insert data into database.
After adding the data it’s time to tell our database to
save our changes, for this write,
db.SaveChanges();
This will add a row to our table with the provided data.
Complete code will look like :
protected void btnRegister_Click(object sender, EventArgs e)
{
db_OrderMangEntities db = new db_OrderMangEntities();
tbl_Vender tbl = new tbl_Vender();
tbl.VenderName = "Kumar";
tbl.VenderContact = 656789;
db.tbl_Vender.AddObject(tbl);
db.SaveChanges();
}
Update
Object in Entity:
To update any row, we need to first find that row.
For that we have to use LINQ with enitites.
The Syntax will be :
tbl_Vender tbl1 = db.tbl_Vender.Where(i =>
i.VenderName == "Kumar").First();
Here I am searching with vendorName you can use any property.
After this we will have tbl1 as the object of that row
which is to be updated.
Now assign the new values to the tbl1 object.
For Example :
tbl1.VenderName = "Gaurav";
After this just tell the database to save
our changes.
db.SaveChanges();
Note , here we are not adding another object to the table
as it will add another row, but we just need to update it.
Deleting
object:
Same first we need to find the row to be deleted .
Now write,
db.tbl_Vender.DeleteObject(tbl1);