Hi I am new to programming in asp.net with c#. I am using visual studio 2010. I am trying to insert data entered by a user into the database.

My code is as follows:

adsStudents.InsertParameters["Stu_ID"].DefaultValue = txtStudID.Text.ToString();
        adsStudents.InsertParameters["Stu_Name"].DefaultValue = txtName.Text.ToString();
        adsStudents.InsertParameters["Stu_Passwd"].DefaultValue = txtPasswd.Text.ToString();
        adsStudents.InsertParameters["Stu_Prog"].DefaultValue = ddlProgramme.SelectedValue.ToString();
        adsStudents.Insert();

        //add a record in the majors table for each major per student
        adsMajors.InsertParameters["Stud_ID"].DefaultValue = txtStudID.Text.ToString();
        foreach (ListItem item in cblMajors.Items)
            if (item.Selected){
                adsMajors.InsertParameters["Stu_Majors"].DefaultValue = item.Value.ToString();
                adsMajors.Insert();
            }

It doesn't give any errors when compiled but it gives this message when run: Use the New keyword to create the instance. This code worked fine with Visual Web Developer.

Can someone please explain what's wrong and how to correct it.

Create new object instance message is for line 8

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.