Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
C#
private void cmdSave_Click(object sender, EventArgs e)
        {

            dt = hRDataSet.Tables["empdetails"];
            dr = dt.NewRow();
            


                dr[0] = txtccode.Text;    //argumentexception was unhandled
                dr[1] = txtEmployeeName.Text;
                dr[2] = txtAddress.Text;
                dr[3] = txtState.Text;
                dr[4] = txtCountry.Text;
                dr[5] = cbDepartment.SelectedItem;
                dr[6] = cbDesignation.SelectedItem;
                dt.Rows.Add(dr);
                empdetailsTableAdapter.Update(hRDataSet);
                txtccode.Text = System.Convert.ToString(dr[0]);
                txtccode.Enabled = false;
                txtEmployeeName.Enabled = false;
                txtAddress.Enabled = false;
                txtState.Enabled = false;
                txtCountry.Enabled = false;
                cbDepartment.Enabled = false;
                cbDesignation.Enabled = false;
                this.empdetailsTableAdapter.Fill(this.hRDataSet.empdetails);
                cmdAdd.Enabled = true;
                cmdSave.Enabled = false;
            }
Posted
Updated 6-Sep-12 3:16am
v2
Comments
[no name] 6-Sep-12 9:27am    
dr is not an array so dr[0] makes no sense.
pinky_sood 6-Sep-12 9:28am    
than what is the way? to store data
deepakaitr12345 8-Sep-12 4:56am    
you can use the approch like this if you having the datatable to save in database

1)Create the generic Ilist like
IList<testmodel> testList= new List<testmodel>();

2)Create the object of your model and initialise the constructure fo your model class under the for loop

like below

for (int i = 0; i < grdTest.Rows.Count; i++)
{

testModelObject = new testModel(value1,value2,value3));

testList.Add(testModelObject);
}

and initialse the values in the constructure
apply the for loop on the insert into statement and your problem get resolved.

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900