The code is incomplete and you have not explained the problem. It is your responsibility to provide enough code for the community to reproduce this issue. Otherwise, it is up to you to use the standard debugging tools and find the source of the problem.
var package = (from c in ctx.packages
where c.tbl_id = (HiddenField1.Value)
Can your code compile successfully? Shouldn't it be "== "after where?
I tested your code, it can be successfully updated.
Please try to debug your code, and make sure it can get the value of the control in the code behind.
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
I have applied your given code . Getting 2 errors. 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' "
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();
Fillgridview();
}
}
Error CS0742 A query body must end with a select clause or a group clause".
sanam13
from c in ctx.packages where c.tbl_id = (HiddenField1.Value)
sanam13
from c in ctx.packages where c.tbl_id = (HiddenField1.Value)
select c)
Why are your 2 queries different? you should add "select c" in your query.
sanam13
"Error CS0029 Cannot implicitly convert type 'string' to 'decimal' "
This error is because HiddenField1.Value is of type string, and tbl_id is of type decimal, so you only need to do type conversion.
Convert.ToDecimal (HiddenField1.Value)
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Now i again tried Ur given code. Now the error occur on this code.
decimal Tbl_id = Convert.ToDecimal(HiddenField1.Value);
Error is 'Input string was not in a correct format.'
Please make sure that the value in HiddenField1 is of type decimal.
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
but i want to update all rows. Please suggest me that method.
If you want to update all rows, then you need to traverse all the data. here a demo for you as a reference.
var idList=new int[]{1, 2, 3, 4};
using (var db=new SomeDatabaseContext())
{
var friends= db.Friends.Where(f=>idList.Contains(f.ID)).ToList();
friends.ForEach(a=>a.msgSentBy='1234');
db.SaveChanges();
}
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Sir this is also a static method which u provided in this code we also first declare rows
{1,2,3,4} like this and i want dynamic method. Please execute the code through hiddenfield control and using label or provide any method sir.
Sir this is also a static method which u provided in this code we also first declare rows
{1,2,3,4} like this and i want dynamic method. Please execute the code through hiddenfield control and using label or provide any method sir.
According to your aspx code, there are no multiple rows, so I can’t understand what it means to update multiple rows and can only provide you with a demo.
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
19 Points
84 Posts
Want to update data through entity framework in asp.net c#
Jun 22, 2020 06:47 AM|sanam13|LINK
All-Star
53041 Points
23621 Posts
Re: Want to update data through entity framework in asp.net c#
Jun 22, 2020 11:09 AM|mgebhard|LINK
The code is incomplete and you have not explained the problem. It is your responsibility to provide enough code for the community to reproduce this issue. Otherwise, it is up to you to use the standard debugging tools and find the source of the problem.
Member
19 Points
84 Posts
Re: Want to update data through entity framework in asp.net c#
Jun 22, 2020 11:23 AM|sanam13|LINK
Contributor
3370 Points
1409 Posts
Re: Want to update data through entity framework in asp.net c#
Jun 23, 2020 03:28 AM|samwu|LINK
Hi sanam13,
Can your code compile successfully? Shouldn't it be "== "after where?
I tested your code, it can be successfully updated.
Please try to debug your code, and make sure it can get the value of the control in the code behind.
Best regards,
Sam
Member
19 Points
84 Posts
Re: Want to update data through entity framework in asp.net c#
Jun 23, 2020 06:44 AM|sanam13|LINK
Hlo sir
I have applied your given code . Getting 2 errors. 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' "
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(); Fillgridview(); } }
Contributor
3370 Points
1409 Posts
Re: Want to update data through entity framework in asp.net c#
Jun 23, 2020 08:54 AM|samwu|LINK
Hi sanam13,
Why are your 2 queries different? you should add "select c" in your query.
This error is because HiddenField1.Value is of type string, and tbl_id is of type decimal, so you only need to do type conversion.
Best regards,
Sam
Member
19 Points
84 Posts
Re: Want to update data through entity framework in asp.net c#
Jun 23, 2020 09:13 AM|sanam13|LINK
Now i again tried Ur given code. Now the error occur on this code. decimal Tbl_id = Convert.ToDecimal(HiddenField1.Value);
Error is 'Input string was not in a correct format.'
Please execute it sir.
Contributor
3370 Points
1409 Posts
Re: Want to update data through entity framework in asp.net c#
Jun 23, 2020 09:19 AM|samwu|LINK
Hi sanam13,
Please make sure that the value in HiddenField1 is of type decimal.
Best regards,
Sam
Member
19 Points
84 Posts
Re: Want to update data through entity framework in asp.net c#
Jun 23, 2020 10:52 AM|sanam13|LINK
With your reference sir i have added a value in code <asp:HiddenField ID="HiddenField1" runat="server" Value="69" />
value = 69 is a tbl_id of one row but i want to update all rows. Please suggest me that method.
Contributor
3370 Points
1409 Posts
Re: Want to update data through entity framework in asp.net c#
Jun 24, 2020 02:36 AM|samwu|LINK
Hi sanam13,
If you want to update all rows, then you need to traverse all the data. here a demo for you as a reference.
Best regards,
Sam
Member
19 Points
84 Posts
Re: Want to update data through entity framework in asp.net c#
Jun 24, 2020 06:51 AM|sanam13|LINK
Sir this is also a static method which u provided in this code we also first declare rows {1,2,3,4} like this and i want dynamic method. Please execute the code through hiddenfield control and using label or provide any method sir.
Contributor
3370 Points
1409 Posts
Re: Want to update data through entity framework in asp.net c#
Jun 25, 2020 09:15 AM|samwu|LINK
Hi sanam13,
According to your aspx code, there are no multiple rows, so I can’t understand what it means to update multiple rows and can only provide you with a demo.
Best regards,
Sam