Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Updating data through hidden field control using entity framework in c# error occurs?

$
0
0

Hlo 

I want to update all records but  Error occur on Hiddenfield1.Value property. Errors are "Error CS0742 A query body must end with a select clause or a group clause". 

"Error CS0029 Cannot implicitly convert type 'string' to 'decimal' "

 Here is my code 

Please execute it 

Aspx<asp:Content ID="Content1" ContentPlaceHolderID="title" runat="server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server"></asp:Content><asp:Content ID="Content3" ContentPlaceHolderID="body" runat="server"><div style="margin-top:30px; margin-left:20px"><asp:HiddenField ID="HiddenField1" runat="server"  /><h1><strong style="color:black">Entity Fm 6.0</strong></h1>    <hr /><table><tr><td><span style="color:black">Package Name</span><br /><asp:TextBox ID ="tb_name"  runat="server" Width="200px"   /><br /></td><td><span style="margin-left:25px; color:black">Reward<br /></span><span style="margin-left:25px"><asp:DropDownList ID="dd3" runat="server" Width="200px" DataTextField="reward"></asp:DropDownList></span> <br /></td><td><span style=" margin-left:25px; color:black">Remarks</><br /></span><span style="margin-left:25px"><asp:TextBox ID="tb_remarks"  runat="server" Width="410px" /></span> <br /></td></tr><tr>   <td>     <br /> <asp:Button ID="BT_submit" runat="server"  Text="Submit" style="border-radius:5px" Height="35px" Width="80px"   OnClick="BT_submit_Click" BackColor="#3366CC" BorderColor="#3366CC" ForeColor="White"  /></td><td><br /><asp:Button ID="BT_update" runat="server"   Text="Update" style="border-radius:5px; margin-left:1.5em" Height="35px" Width="80px"   OnClick="BT_update_Click" BackColor="#3366CC" BorderColor="#3366CC" ForeColor="White" /></td><td><br /><asp:Button ID="BT_delete" runat="server" Text="Delete" style=  " margin-left:1.6em;    border-radius:5px" Height="35px" Width="80px"  OnClick="BT_delete_Click" BackColor="#3366CC" BorderColor="#3366CC"  ForeColor="White" /> </td></tr></table></div>C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Entity;
using System.Data;

namespace WebApplication14
{

    public partial class Model : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
               
            }
        }

        public void Fillgridview()
        {
            using (SchoolEntities2 ctx = new SchoolEntities2())


                Gv8.DataSource = (from SchoolEntities2 in ctx.packages select SchoolEntities2).ToList();
                Gv8.DataBind();
        }
        public void Filldropdownlist()
        {
            using (SchoolEntities2 ctx = new SchoolEntities2())


                dd3.DataSource = (from SchoolEntities2 in ctx.packages select SchoolEntities2).Distinct().ToList();
               dd3.DataBind();
            dd3.Items.Insert(0, new ListItem() { Text = "Select", Value = "0" });
        }
        protected void BT_submit_Click(object sender, EventArgs e)
        {

            int status = 0;
            using (SchoolEntities2 ctx = new SchoolEntities2())
            {
                ctx.packages.Add(new package()
                {

                    package_name = tb_name.Text,
                    reward = dd3.SelectedItem.ToString(),
                    remarks = tb_remarks.Text,
                    by_whom = Session["username"].ToString(),
                    date_time = System.DateTime.Now.ToLocalTime()

                }) ;

                
                status = ctx.SaveChanges();
                Fillgridview();
                
}
        }

        protected void BT_update_Click(object sender, EventArgs e)
        {
           
            using (SchoolEntities2 ctx = new SchoolEntities2())
            {

                var std = (from c in ctx.packages where c.tbl_id = (HiddenField1.Value));

               
                std.package_name = tb_name.Text;
                std.reward = dd3.SelectedValue.ToString();
                std.remarks = tb_remarks.Text;


                ctx.Entry(std).State = System.Data.Entity.EntityState.Modified;
                ctx.SaveChanges();
                
            }

        }


        protected void BT_delete_Click(object sender, EventArgs e)
        {
            using (SchoolEntities2 ctx = new SchoolEntities2())
            {
                

                var std = ctx.packages.First<package>();
                ctx.packages.Remove(std);
                ctx.SaveChanges();
            }
        }


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>