Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9163321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:25:09+00:00 2026-06-17T14:25:09+00:00

I am trying to update database table based on text-box values.But i am unable

  • 0

I am trying to update database table based on text-box values.But i am unable to get new modified values in database.

Here is my code which displays information in text-boxes coming from database

protected void Info()
{
    string sID = Request.QueryString["ID"];
    string sSql = "select * from [fn_Items]('"+sID+"')";
    DataTable tbl1 = new DataTable();
    string sEr = myClass.FillupTable(sSql, ref tbl1);
    if (tbl1.Rows.Count > 0)
    {
        DataRow rd = tbl1.Rows[0];
        txtName.Text = rd["Name"].ToString();
        txtCategory.Text = rd["Category"].ToString();
        DateTime mStart;
        DateTime mFinish;
        Boolean b = false;

        b = DateTime.TryParse(rd["start"].ToString(), out mStart);
        b = DateTime.TryParse(rd["end"].ToString(), out mFinish);
        txtStart.Text = mStart.ToString("dd-MMM-yyyy");
        txtend.Text = mFinish.ToString("dd-MMM-yyyy");
        txtDescription.Text = rd["Description"].ToString();

    }
}

Now when the user modifies the text-box data and clicks save, the data should change in the database. Here is my click_event:

protected void btnSave_Click(object sender, EventArgs e)
{
    using (SqlConnection sqlConn = new 
        SqlConnection("Data Source=MSSQLSERVER2008;Initial Catalog=Items_2;Persist Security Info=True;User ID=sa;Password=password"))
    {

        string query = "UPDATE tbl_Items SET Name = @Name,Category=@Category,start = @start, end = @End,Description = @Description where ID = @ID ";
        SqlCommand cmd = new SqlCommand(query, sqlConn);
        cmd.Parameters.AddWithValue("@ID",txtID.Text);
        cmd.Parameters.AddWithValue("@Name", txtName.Text);
        cmd.Parameters.AddWithValue("@Category", Category.Text);
        cmd.Parameters.AddWithValue("@start", txtStart.Text);
        cmd.Parameters.AddWithValue("@end",txtend.Text);
        cmd.Parameters.AddWithValue("@Description", txtDescription.Text);
        cmd.Connection.Open();
        try
        {
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw new Exception("Error " + ex.Message);
        }

    }

Here while updating, in text-boxes I am getting the values present in the database where I need to get the modified values. How do I get the modified values instead?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:25:10+00:00Added an answer on June 17, 2026 at 2:25 pm

    Page load event fire first before firing Click event of btnSave. Using IsPostBack eliminate that problem.

    protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack)
       {
         Info();
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to insert status update into my database in table called blabbing, but
I'm trying to update my database table with PDO, but to avoid security leaks,
I am trying to update a database with values from a csv file, the
I'm making a 'post text' app and trying to update my database with name
I'm trying to update a row in my database but it's not running. Below
I am trying to update an existing record in a database using CoreData, but
I would like to update multiple columns in one table based on values in
I am fairly new to database programming and am trying to get a basic
I am trying to create a table based on the Magento database structure. I
I'm trying to run an update query that updates one table based on rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.