.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

Updating the Database

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :ASP.Net

Hello everbody,

I have a database need to be updated through a web page

 this web page contains

1-Dropdownlist that shows certain categories

2-textbox to write the updated name of the selected category in the previous dropdown list

3-the button Update to do the updating.

and this is the code:

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)


"SELECT distinct Category FROM CategoryNames";


protected void Button2_Click1(object sender, EventArgs <

View Complete Post

More Related Resource Links

Help with updating database with values from Repeater control using c#


Hello, I'm new to ASP.NET 3.5 with C#. I really need some help.

I used a Repeater control to create a simple (editable) list where, when a user logs in, they can edit their list of expenses.  The ASP page works fine.

 My issue is with the code-behind.  I am really confused with how to extract the values from the repeater control. The FindControl method does not seem to be working.  Also, the code I am using resets my 'Amount' values back to 0.00. (0.00 is the amount the user sees when they first encounter the page).

 Here's a portion of the code on the ASP page:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"





<td><asp:Label ID="lblExpId" runat="server"  Text='<%# Bind("ExpId") %>'></asp:Label> </td>

 <td><asp:Textbox ID="lblExpense" runat="server" Width= "190px" Text='<%# Bind("ExpenseName") %>'></asp:Textbox> </td>

 <td><asp:Textbox ID="txtAmount" runat="server" Width= "100px"

Cannot connect to the configuration database after updating SQL SP3

hi, We're using WSS 3.0 with SQLExpress 2005. Because Symantec Backup Exec 2010 also install on this server, so I have to update to SQL Service Pack 3. But after updated to sql service pack 3 and installed Backup Exec 2010, I cannot connect to sharepoint. When I access to Central Administration, an error appears: "Cannot connect to the configuration database" I followed this instruction: http://support.microsoft.com/kb/823287 but the problem still persists. Does anyone know how to solve this problem? Thanks

UpdateModel() confusion - not updating database


I'm quite new to asp.net and even newer to mvc so i hope this is an easy one for you guys.  I was trying to follow the MvcMusicStore example and apply it to my own project.


My VideoManagerController

        public ActionResult Edit(int id)
            var vid = pokerDB.videos.Single(a => a.id == id);

            return View(vid);

        // POST: /VideoManager/Edit/5

        public ActionResult Edit(int id, FormCollection formValues)
            var video = pokerDB.videos.Single(a => a.id == id);

                // save video

                return RedirectToAction("Index");
                Debug.WriteLine("suck da ***");
                return View(video);

Edit View

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SiteMaster.Master" Inherits="System.Web.Mvc.ViewPage<PokerTraining.Models.video>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">

convert string to int before updating database table?


I have a form in which I display data from a database table, change the data and then update the database table. The form consists of textboxes, so all data displayed in the form is string. However - one data is int in the database table (the rest is varchar), so I need to convert it from string to int when I update the database table. How do I do it?

protected void SaveProd_Click(object sender, EventArgs e)
        string BildID = TextBoxProdPictID.Text;
        string namn = TextBoxProdName.Text;
        string kategori = TextBoxProdCategory.Text;
        string stl = TextBoxProdSize.Text;
        string pris = TextBoxProdPrice.Text;
        string iLager = TextBoxProdNumberOf.Text; //this is int in the database table

        SqlConnection conn = new SqlConnection(config);
      //  conn.Open();
        string sql = "UPDATE Produkter SET kategori ='" + kategori + "', namn ='" + namn + "', stl ='" + stl + "', pris ='" + pris + "', iLager ='" + iLager + "' WHERE ID ='" + ID + "'";
        SqlCommand comm = new SqlCommand(sql, conn);//Conversion failed when converting the varchar value '__Page' to data type int.
        SqlDataReader dr = comm.ExecuteReader(); 

        //clear t

Updating the viewstate object before saving it to the database


I have overridden the following methods:


SavePageStateToPersistenceMedium(object viewState) 

in a class that my page derives from, so that the viewstate can be stored in DB.

Now, on page_load of my page, I am checking what control caused a postback & based on that I am forcing execution of 2 button click events in a row (by overloading those click events & calling them explicitely), but the behaviour I want is as if the execution of those 2 button click events went through the regular page life cycle.

Here is the sequence of events that happen in typical page life cycle & notice I want to alter behaviour at step 4 (on load):

1) Initialization

2) LoadViewStateData (here the viewstate is loaded from my database using the overridden LoadPageStateFromPersistenceMedium)

3) LoadPostBackData

4) Load

Here, I would like to force execution of 2 button_click events based on whether a particular control posted back.

       4.1) imgBtnPrev5_Click()

       4.2) imgBtnPrev4_Click()

Now, when the imgBtnPrev5_Click() is executed, the viewstate is already loaded, so we are fine. But after execution of imgBtnPrev5_Click(), I would like to update the viewstate object in memory & then call the o

Database update, treeview is not updating


I have a treeview that i fill from a database, when i add a new row to a database, the treeview is not updating.
Even the reload of an internet explorer doesn't help, It does updates only after i press stop debugging button and turn it on again.
Here is the code:

    private void MenusBuilder()
        //Parent menu extraction
        DataSet1.TreeItemRow[] cr = GetTreeItemRows();

        StringBuilder sb = new StringBuilder();
        sb.AppendLine(@"<?xml version=""1.0"" encoding=""utf-8"" ?>");
        sb.AppendLine(@"<div id=""menu"">");

        string XmlSiteCreator = CreateXmlDataSource(cr, sb);

        XmlDataSource1.Data = XmlSiteCreator; //Tree Menu
        TreeView1.DataSourceID = XmlDataSource1.ID;

    public static DataSet1.TreeItemRow[] GetTreeItemRows()
        using (DataSet1TableAdapters.TreeItemTableAdapter tita = new DataSet1TableAdapters.TreeItemTableAdapter())
            DataSet1.TreeItemDataTable tidt = tita.GetData();
            DataSet1.TreeItemRow[] pmr = (from f in tidt select f).ToArray();
            return pmr;

(XmlSiteCreator returns the right xml f

Updating sql express 2008 database table from an XML file.


I'll start off with the usual caveats.. new to the forum, new to programming, not a programmer by trade..just a dabbler


A little background..


I run a hockey pool for me and a few friends. I currently use Excel to produce everything. Every week I download a csv file from a stats reseller, update my pool, then run some macros to create web pages and upload those to my site. It works alright but I want to take my pool/site to the next level. So I decided to do a new site using ASP.NET and sql express.


My plan is to download an XML file from the same reseller and update my "Player" table every week with the "new" stats.


I used a Dataset, SqlDataAdapter, and the XML file from the reseller to populate my "Player" table in the beginning. It was pretty slick, pretty easy. My problem is I can't seem to figure out how to update my "Player" table with my new stats.


First I tried using the same Dataset/SqlAdapter but it threw a Primary Key exception, saying I couldn't insert that ID because it was already existing in the table. I can fill my dataset from the "Player" table change things and save it back to the "Player" table..but that's not what I want to do.


In my min

Updating database from datagrid


Does anyone know how i can take a row data in a datagrid and insert it into a table on my database?


I have the following code, but it doesnt seem to be working.


 Dim strConn As String = "Data Source="
        Dim strSQL As String
        Dim pc As SqlParameterCollection
            ' Set the InsertCommand
            strSQL = "INSERT INTO table ([Username], [Category], [Company], [CategoryType]) VALUES (@Username, @Category, @Company, @CategoryType)"

            Dim cn As New SqlConnection(strConn)
            Dim da As New SqlDataAdapter(strSQL, cn)
            da.InsertCommand = New SqlCommand(strSQL, cn)
            pc = da.InsertCommand.Parameters
            pc.Add("@Username", SqlDbType.Int, 0, "Username")
            pc.Add("@Category", SqlDbType.SmallInt, 0, "Cat

Updating Database with gridview control


I am sure I am not the first to ask this question but I cannot find an answer in these or any other forums. I guess I am not wording the question right.

In short I have a gridview populated but a database via an SQLDatasource. I have an Edit column in the datagrid and an updatequery in the datasource. When the Edit is click the line goes into edit mode, the user then clicks Update and I get an error. 

Could not find control 'DropDownList1' in ControlParameter 'Frequency'.

The only complication is that there is a drop down control when the "EDIT" column is selected. The dropdownlist gets it list from another SQLDatasource. This all works fine.

Here is the code snip:

        <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateEditButton="True" 

            AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="

C#: How to store real-time updating measurements in a database (C#)

I have real-time updating measurements (for each second some new values).

Task: I have to store these real-time updating measurements in a database.

Question: Since I am working with C#, I have 2 basic questions:
(1) How to store real-time updating values in C# (within in database framework)?
(2) Should I use MySQL as database?

Thanks in advance,

Multiple database support with Entity Framework

One of the features introduced in Entity Framework is being database independent. Which mean each database provider can support Entity Framework by implementing its provider.

This feature allows you build applications independent from the underplaying database provider. In this post I'm going to show how to build an application that support multiple databases using same conceptual model made by Entity Framework.

Export Visio Database Table Names to Excel

If you use the Enterprise Architect edition of Microsoft Visio for data modeling regularly, then there is a good chance that at some point you've wanted to export just the table names into Excel. You might want to do this to map logical ERD entities to physical data model tables, track project status by entity, or track overlap between database versions.

MS SQL Server: Disconnect Users From Database - Kill User Session

If you ever wanted to restore your database from a SQL backup file (.bak), but there are still users connected to your database, the backup operation will fail causing the error: Exclusive access could not be obtained because the database is in use.

Publishing SQL Server Database using Publishing Wizard : Tips & Tricks

We can use SQL Server Publishing Wizard to deploy our local Database to remote hosting server/production server.This feature is available in SQL Server 2008/VWD 2008.

Below is the complete step by step guide of this process.

Adding Rows in GridView without using a Database

This article describes on how to add rows in GridView without using a database. Basically the GridView will be populated with data based on the values entered in the TextBox on Button Click and retain the GridView data on post back.

Adding Multiple Columns and Rows in GridView without using a Database

This article describes on how to add multiple columns and rows in GridView without using a database. Basically the GridView will be populated with data based on the values entered in each TextBoxes on Button Click and retain the GridView data on post back.

ASP.NET Database Tutorial

This tutorial will show you how to display data using the .NET GridView Control, ASP.NET 2.0 and VB.NET

The GridView control is a powerful tool and is simple to implement.

First, you will need to import the System.Data.SqlClient namespace.
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