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 7863987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:39:12+00:00 2026-06-02T23:39:12+00:00

I have some trouble to update my sql server 2005 database when i use

  • 0

I have some trouble to update my sql server 2005 database when i use parameters.Here you can see the code that normally has to work.I precise that i already make others treatments such as insert into and it worked perfectly.

myCommand.Parameters.AddWithValue("@Pk", this.pk);
myCommand.Parameters.AddWithValue("@Titre", this.titre);
myCommand.CommandText = "Update Action set titre=@Titre where pk=@Pk";

//Execute la commande
myCommand.ExecuteNonQuery();

EDIT:When i use hard code such as:

myCommand.CommandText = "Update Action set titre='title' where pk=@Pk";

it works…

  • 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-02T23:39:13+00:00Added an answer on June 2, 2026 at 11:39 pm

    I don’t know where you went wrong this is the working code for me

    string strCon = @"Data Source=SYSTEM19\SQLEXPRESS;Initial Catalog=TransactionDB;Integrated Security=True";

    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SqlConnection cn = new SqlConnection(strCon);
                SqlCommand cmd = new SqlCommand("select * from tblTransaction1", cn);
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataSet ds = new DataSet();
                da.Fill(ds);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    txtName.Text = ds.Tables[0].Rows[i]["FirstName"].ToString();
                    txtName1.Text = ds.Tables[0].Rows[i]["LastName"].ToString();
                }
            }
        }
    

    Button click code

    protected void btnInsert_Click(object sender, EventArgs e)
    {
        SqlConnection cn = new SqlConnection(strCon);
        obj1.FirstName = txtName.Text;
        obj1.LastName = txtName1.Text;
        if (obj1.upDate(cn))
        {
    
        }
    }
    

    Sample class code file

    private bool m_flag = false;
            private string strFirstName;
            private string strLastName;
    
            public string FirstName
            {
                get { return strFirstName; }
                set { strFirstName = value; }
            }
    
            public string LastName
            {
                get { return strLastName; }
                set { strLastName = value; }
            }
    
    public bool upDate(SqlConnection con)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            if (con.State != ConnectionState.Open)
            {
                con.Open();
            }
    
            try
            {
                cmd.Parameters.AddWithValue("@Fname", FirstName);
                cmd.Parameters.AddWithValue("@Lname", LastName);
                cmd.CommandText = "Update tblTransaction1 set LastName=@Lname where FirstName=@Fname";
                if (cmd.ExecuteNonQuery() > 0)
                {
                    m_flag = true;
                }
            }
            catch
            {
    
            }
            return m_flag;
        }
    

    Sample Images

    Form With Data from SQL

    Database data before update

    Changing Lastname

    after update

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble to update some rows in SQL Server (2005 and 2008). Often,
I'm having some trouble with an SQL statement that have to find the number
I have an existing SQL Server database whose structure I can't really change, although
I'm have some trouble with the fulltext CONTAINS operator. Here's a quick script to
Im having some trouble getting the syntax right. I have a movie clip that
Trying to use nhibernate on sql-server compact edition for unit testing and having some
I have a basic CMS where a user can update a database of articles
I have some trouble when trying to update a table by looping cursor which
I have some trouble with a git repository that contains several submodules. The super
I have a big SQL Server database I want to connect to and my

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.