Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

"ArgumentOutOfRangeException" for binding combobox with datatable.

"ArgumentOutOfRangeException" for binding combobox with datatable.

"ArgumentOutOfRangeException" for binding combobox with datatable.

Hello everybody,

I'm new on this forum and I would really appreciate some help with my project.I bonded my database table "Courses" to a combobox. So far so good,but when i try to register a student and i click the "Register" button after i selected an item from the combobox,the program stops working and shows an error saying "ArgumentOutOfRangeException".I have tried different possibilities,but nothing is working.Maybe someone can help me figure it out.This is the code for the combobox:

private void FillDropDownList()

DataRow dr;
SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\User\source\repos\VIAUniversityCollegeAttendanceApp\VIAUniversityCollegeAttendanceApp\DatabaseAttendanceStudents.mdf;Integrated Security=True;Connect Timeout=30");

SqlCommand cmd = new SqlCommand("select * from Courses ", conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
dr = dt.NewRow();
dr.ItemArray = new object[] { 0, "--Select Course--" };
dt.Rows.InsertAt(dr, 0);
comboBoxCourses.ValueMember = "courseID";
comboBoxCourses.DisplayMember = "coursename";
comboBoxCourses.DataSource = dt;

The method is called after InitializeComponent() in StartUp(){}.

RE: "ArgumentOutOfRangeException" for binding combobox with datatable.

It sounds like you're saying that the code above works fine (loading the combobox), but then breaks when you click the Register button. What's the code for that button's click event?


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close