.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Update a record in a table?

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :ASP.Net
HiI've been playing around with MVC lately, and was wondering how you could do this:I have a view that displays a list of products, and against each product is a list of categories (in a combobox). I'm trying to find out how you can update a product's category when you select a category in the list. I know you could do something fairly simple with jQuery, but I'm trying to understand how submitting forms works with MVC.Here's what I currently have:// Controller public ActionResult Index() { List<Product> products = _productRepository.GetProducts(); List<ProductCategory> categories = _productRepository.GetCategories(); ProductsViewModel viewModel = new ProductsViewModel { Products = products, ProductCategories = new SelectList(categories, "Id", "Description") }; return View(viewModel); } // ViewModel public class ProductsViewModel { public List<Product> Products { get; set; } public SelectList ProductCategories { get; set; } } // View <% using (Html.BeginForm()) { %> <table> <tr> <th>Id</th> <th>Description</th> <th>Category</th> </tr> <% foreach (var product in Model.Products) { %> <tr> <td><%: product.Id%></td> <td><%:

View Complete Post

More Related Resource Links

After Update trigger for a record which does not exist in table.


Hi Everyone,

I have a update query which sometimes results in no row updated (i.e. 0 rows updated),

I want to apply after update trigger on it , if update results in 0 row affected then insert that record,

I have written following trigger for it,

ALTER TRIGGER [dbo].[table1]

   ON  [dbo].[table1]





            SET NOCOUNT ON;

execute update timedout expires , table with trigger due to recovery of database


I have table A in database A  , in table A i have trigger to insert record to database B table A, each update and insert of database A -table A, triiger fire and insert record in database B table A, when i try to update some times asp.net application gives error

"Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding."

and then error log says System.Data.SqlClient.SqlException: Database 'database B is being recovered. Waiting until recovery is finished.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean ret

Can't perform Create, Update or Delete operations on 'Table(outbox)' because it has no primary ke



I'm a beginner in asp.net and I have some problem inserting data into sql server 2005 with linq.


my code is : 


        Dim Result As New SMS.SendResult
        If Result.status = 0 Then
            Label1.Text = "Your Message Sent Successfuly"
            Dim db As New IGSSDataContext
            Dim out As New outbox With {.ClientID = intRandomNumber, .From = User.Identity.Name, .TO = TextBox1.TabIndex, _
            .Time = Now, .Message = Message}
            out.ID = (ID)
            TextBox1.Text = ""

select max record to join another table sybase

select a.pono,(select (user) from user where userid=a.userid having date=max(date)) as user from a inner join b on a.no=b.no  in the result , i have selected the same id and retrieve two records every thing are same except the date how can i select the record out of two record which date is max date as the where Clasuse to select correct user poid    date                name 1        12/08/2010      Mary 1        20/08/2010      Peter   now i would like to select name which id=1 and date is max and then use the name to join another table because name is foreign key  

update data on table

i have  100000 record  found in the  tha table and  i want  to update the column SocialState when found male he replace  the text male to 1 and when foun Female  he replace the text to 2   update [Drugs].[db_accessadmin].[Data] set SocialState='1' where SocialState='Male' update [Drugs].[db_accessadmin].[Data] set SocialState='2' where SocialState='FeMale' he give me this message "(0 row(s) affected)"

Delete Record From Table A that Is Not In Table B

I have two tables; Table A id, name 101, jones 102, smith 103, williams 104, johnson 105, brown 106, green 107, anderson   Table B id, name, city, state 101, jones, des moine, Idaho 103, williams, Corvallis, Oregon 104, johnson, Grand Forks, North Dakota 105, brown, Phoenix, Arizona 107, anderson, New York, New York   I need to delete records from Table A that are not in Table B.  My front end is writen in .net and I am using Data Access Layer along with a Business Logic Layer for data interaction.   I have tried at least seven variations of joining, right outer join, left outer join resulting in wiping our the entire table or nothing at all; not to mention deleting the record that ought to remain and keeping the record that needs to be deleted!   In my BLL I tried to capture the rowsAffected for the deletion by using-without success. Dim rowsAffected As Integer = Adapter.ID_Deletion(ID) If rowsAffected = 1 Then Exit Function Else Return rowsAffected = 1 End If   Please help.   MsMe.

How can i update treeview root node every time based on the record entries

Hi all, I will have an mdi form and with a treeview which has it's initial property as visible =false. If i select an option from menu a child form will exists i will fill some details and click on save when ever click on save i will make the root node of the treeview to some name as File[batch count:0]. Now if i select another option from menu another form will appear and if i fill it with some details and click on save i would like to change the root node name to File[batch count:1] and a child node should exists with some name

How to send record(which is a weblink) from a table to the value of the variable in SSIS package and

Hi Folks, I have table called Table1 with columns, col1 and col2 with col1 having weblinks for the report and col2 the name of the report. Now, i have a package with a variables var1 and var2 which should get the col1 and col2 values respectively from table1 and send it through an email. if the weblink gets updated in the table, package should send the updated link. i know the reverse way of it but trying to do somethig like this. Appreciate any help from you guys. Thanks

Record is already exists in Dimension table but still Kimball SCD Component is Identifying it as a n

Hi I have loaded Dimension table. Now even if the record already exists in my dimension table , every time I run package Kimball method SCD component is identifying as a new record. Please advise. Thanks, Anuja

Cannot add record in table using NHibernate

Hi there!I'm new to NHibernate and I need help on this issue.No records where inserted in my SQL Table after committing the transaction or after the .Flush() method. I checked the code and it follows the correct sequence of codes. I can't seem to find any other way where the error fails.

Update an accumlating shapshot fact table

This is my first time implmenting an accumulating snapshot fact table and I require some guidance. Accumulating snapshot fact tables show the status at any given moment. It is useful to track items with certain life time, for example: status of order lines.eg everytime there is new piece of information about a particular purchase, we update the fact table record. We only insert a new record in the fact table when there is a new purchase requisition. What I really need to know is how best to handle the updates.  This really feels very similar to managing SCD-1's in dimension processing! Anyone able to advise? thanks in advance Here is a perfect example we can use  http://blog.oaktonsoftware.com/2007/03/accumulating-snapshot-use-accumulating.html Figure 1, below, shows an accumulating snapshot for the mortgage application process. The grain of this fact table is an application. Each application will be represented by a single row in the fact table. The major milestones are represented by multiple foreign key references to the Day dimension—the date of submission, the date approved by mortgage officer, the date all supporting documentation was complete, the date approved by an underwriter, and the date of closing.

How we Update DataContext's Table Implicitly in Linq using .Net 3.5..?

Hi All.. My problem is i am working on Linq,as we know to use any table in linq we have to drag and drop it on our datacontext's Designer File,and at run time we got its value,till here no any problem,main point is if any changes in respective data source's schema has made ,then on datacontext we will not get that changes,for it we have to change this datacontext manually by by again drag and drop,it will not happen implicitly when this changes has been made on the data source. so please tell me how i solve this problem so that datacontext change implicitly without any over head  using .net 3.5 . 

Linked server and sensitive to register name of table. Problem with UPDATE.

Hi All. I try to work with table with "sensitive to register" name through Linked Server (MSSQL 2005/2008) and get the problem with UPDATE statement. Reason: MSSQL generates UPDATE statement with "un-quoted" table name. With SELECT/INSERT/UPDATE - no any problems. ----- Linked Database Information: 1. Firebird 2.5 2. OLEDB Provider: IBProvider v3 3. Database dialect: 3 Metadata: CREATE GENERATOR "GEN_ID_TableWithMixName1"; CREATE TABLE "TableWithMixName1" ( TEST_ID INTEGER NOT NULL, "Col" VARCHAR(100), DUMMY_COL INTEGER, CONSTRAINT "PK_TableWithMixName1" PRIMARY KEY (TEST_ID) ); CREATE TRIGGER "BI_TableWithMixName1_TEST_ID" FOR "TableWithMixName1" BEFORE INSERT AS BEGIN IF(NEW."TEST_ID" IS NULL)THEN NEW."TEST_ID" =GEN_ID("GEN_ID_TableWithMixName1",1); END; ------- MSSQL Test 1. MSSQL: select * from IBP_TEST_FB25_D3_V3...TableWithMixName1; IBProvider: Command_Execute   SELECT "Tbl1002"."TEST_ID" "Col1004",         "Tbl1002"."Col" "Col1005",         "Tbl1002"."DUMMY_COL" "Col1006"   FROM "TableWithMixName1" "Tbl1002" No Problem ------- MSSQL Test 2. MSSQL: delete from IBP_TEST_FB25_D3_V3...Tabl

Update Database Record using GridView and Stored Procedure

Hi, I am trying to update record via stored procedure, but i got error at very start point. Problem is when i click on Edit link button within the Gridview it produce error. I can populate values from database fine but its produce error when i click on edit link button. Please see the code below. *********** ASP.net GridView Code I am using *****************<asp:GridView ID="GridView1" runat="server" DataKeyNames="RollID, EmpID" AutoGenerateColumns="False" Width="700px"> <Columns> <asp:TemplateField HeaderText="ApplicationID" Visible="false"> <ItemTemplate> <asp:Label ID="AppsID" runat="server" Visible="false"><%# Eval("RollID") %>'</asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="ReleaseID" Visible="false"> <ItemTemplate> <asp:Label ID="rlsID" runat="server" Visible="false"><%# Eval("EmpID") %></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Roll Name"> <ItemTemplate> <asp:Label ID="rlsVersion" runat="server"><%# Eval("Roll_Name")%></asp:Label> </ItemTemplate> <EditI

How to select bottom record if there is no id in table.

Hi All, I am trying to select the bottom record but there is no id in table. For Example A              B jo             john so             som mo            mon to              tom go              gone

update table using web services

i want to update table using web service file, i am retriving value like this :[WebMethod]    public DataSet getinfo()    {        SqlConnection con = new SqlConnection(@"Data Source=WEBTECHNO1\WEBTECHNO;Initial Catalog=blogsite;Integrated Security=True");        SqlCommand cmd=new SqlCommand("select * from blogenter",con);        SqlDataAdapter da=new SqlDataAdapter(cmd);        DataSet ds=new DataSet();        da.Fill(ds);        return ds;    }anybody tell me how can i update table using this web service , what should return type in update and all these things...

update table with SSIS

  Hi, sorru for my english   I have two tables: intervenant: idInt (primary key) name login (foreign key) (accepting the null) compte: login (primary key) idInt (foreign key) I'd like to know how to do an UPDATE in the table "intervenant" once I filled the login field of the "compte" table.     thanks
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend