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

  • Home
  • SEARCH
  • 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 6637463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:19:06+00:00 2026-05-25T23:19:06+00:00

I am trying to write an update statement for inserting data from asp.net gridview

  • 0

I am trying to write an update statement for inserting data from asp.net gridview to sql server 2005 database.but it is showing me an error, Please tell me how to solve.

cmdUpdate.CommandText = String.Format("Update Products SET ProductName=
{0},UnitsInStock={1},UnitsOnOrder={2},ReorderLevel={3} WHERE ProductID={4} AND 
SupplierID={5}", "productname.Text, unitsinstock.Text, unitsonorder.Text,  
recorderlevel.Text, employeeid.Text, supplierid.Text");

Error is-
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

  • 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-05-25T23:19:07+00:00Added an answer on May 25, 2026 at 11:19 pm

    You missed the arguments,

    For instance,

    str=String.Format("{0} {1}",arg1,arg2);
    

    Do not use hard-coded sql strings. Try to learn/use parameterized queries.

    EDIT:

    string ConnectionString = "put_connection_string";
    using (SqlConnection con = new SqlConnection(ConnectionString))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            string sql = "Update Products SET 
                    ProductName=@ProductName,
                    UnitsInStock=@UnitsInStock,
                    UnitsOnOrder=@UnitsOnOrder,
                    ReorderLevel=ReorderLevel 
                    WHERE ProductID=ProductID AND SupplierID=@SupplierID";
            cmd.CommandText = sql;
            cmd.Connection = con;
            cmd.Parameters.Add("@ProductName", System.Data.SqlDbType.VarChar, 50).Value =productname.Text;
            cmd.Parameters.Add("@UnitsInStock", System.Data.SqlDbType.Int).Value =unitsinstock.Text;
            cmd.Parameters.Add("@UnitsOnOrder", System.Data.SqlDbType.Int).Value =unitsonorder.Text;
            cmd.Parameters.Add("@ReorderLevel ", System.Data.SqlDbType.Int).Value =recorderlevel.Text;
            cmd.Parameters.Add("@ProductID", System.Data.SqlDbType.Int).Value =producteid.Text;
            cmd.Parameters.Add("@SupplierID", System.Data.SqlDbType.Int).Value =supplierid.Text;
    
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
    }
    

    EDIT: What is C# using block?

    1. If the type implements IDisposable, it automatically disposes it
    2. Provides a convenient syntax that ensures the correct use of IDisposable objects.
    3. Avoiding Problems with the Using Statement
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a page in asp.net to update an user object
I'm trying to write a valid mysql statement that would allow me to update
I am trying write a function that generates simulated data but if the simulated
i have an SQL statement wherein i am trying to update the table on
I'm new to linq and I'm trying to write an update statement. I have
I am trying to run this update statement but informix doesn't allow me to.
I am trying to submit data to a database. I have an update form
Trying to find the best way to write this SQL statement. I have a
Im trying to write a procedure to update two tables but im a little
I'm trying to get php to update a MySQL table using UPDATE statement but

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.