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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:50:31+00:00 2026-05-22T15:50:31+00:00

i m making add,edit delete module…For that i have the following code in the

  • 0

i m making add,edit delete module…For that i have the following code in the c#,

private void listOfCompany_Load(object sender, EventArgs e)
    {
        //MessageBox.Show(updID.ToString());
        con.ConnectionString = @"PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\mayur patil\\My Documents\\Dairy_db\\tblCompany_1.mdb";
        con.Open();
        OleDbDataAdapter da = new OleDbDataAdapter();
        DataSet ds = new DataSet();
        string sql = "SELECT * From tblCompany_1 WHERE ID="+updID;

        da = new System.Data.OleDb.OleDbDataAdapter(sql, con);
        da.Fill(ds);
       // dataGridView1.DataSource = ds.Tables[0];
        DataRow dr = ds.Tables[0].Rows.Count;
        textBox1.Text = dr.ItemArray.GetValue(0).ToString();
        textBox4.Text = dr.ItemArray.GetValue(2).ToString();
       /* int t = ds.Tables[0].Columns.Count;
        for (int i = 0; i < cnt; i++)
        {

            dataGridView1.Rows[i].Cells[0].Value = dr.ItemArray.GetValue(0).ToString();
            dataGridView1.Rows[i].Cells[1].Value = dr.ItemArray.GetValue(1).ToString();
            dataGridView1.Rows[i].Cells[2].Value = dr.ItemArray.GetValue(2).ToString();
        }*/


    }

when i debug the application, then on add,edit and delete button, it gives me error at the “DataRow dr = ds.Tables[0].Rows[0];” that “IndexOutOf RangeException was handled” and the error is “There is no row at position 0.”…How should i overcome from this?

  • 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-22T15:50:32+00:00Added an answer on May 22, 2026 at 3:50 pm

    Well that suggests there’s no record with that ID. You should check for that before going ahead and trying to use it. You can use ds.Tables[0].Rows.Count to find out how many rows were returned.

    You should also start using parameterized queries instead of including values directly within the SQL statement you’re building, in order to avoid SQL injection attacks. If the ID is an integer then it probably isn’t a problem here, but generally parameterized SQL queries are the way forward.

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

Sidebar

Related Questions

C# 3.0 Extension methods add extensions to the base Type making calling that method
I have been writing some code that creates a generic blog. Its features are
I'm making a program that allows you to add any class file that extends
I have been making a little toy web application in C# along the lines
I was making an edit to a long existing project. Specifically I added some
I was able to manage rows(add, delete and reorder) of an uitableviewcell in navigation
I am making a table in which you can add aditional rows. When you
I have been tasked with developing a solution that tracks changes to a database.
This is beyond both making sense and my control. That being said here is
I am making a synonyms list that I will store it in database and

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.