Home > database >  Index (zero based) must be greater than or equal to zero and less than the size of the argument list
Index (zero based) must be greater than or equal to zero and less than the size of the argument list

Time:11-11

if (PatnameTB.Text == "" || PatphoneTB.Text == " " || 
    PatadressTB.Text == "" || PatdobTB.Text == "" || 
    PatgenderCB.SelectedIndex == -1 || PatallergiesTB.Text == "" || 
    PatmedhistoryTB.Text == "") 
{
    MessageBox.Show("Missing Data!!!");
}
else
{
    string Name = PatnameTB.Text;
    string Phone = PatphoneTB.Text;
    string Address = PatadressTB.Text;
    string Dateofbirth = PatdobTB.Text;
    string Gender = PatgenderCB.SelectedItem.ToString();
    string Allergies = PatallergiesTB.Text;
    string Patmedhistory = PatmedhistoryTB.Text;
    
    string Query = @"insert into Paitent.Tbl 
    Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')";
    
    Query = string.Format(Query, Name, Phone, Address, Dateofbirth,
                          Gender, Allergies, Patmedhistory);
    Con.SetData(Query);
    ShowPatients();
    MessageBox.Show("Paitent Added!!");

}
             

When i try adding a new patient for testing purposes system refuses to update list but gives me Index (zero based) must be greater than or equal to zero and less than the size of the argument list. Error if anyone can take a look at this I'd be very happy

CodePudding user response:

The error message is telling you exactly what is wrong: your format string has 8 slots ({0} through {7}) but you are only passing 7 arguments.

  •  Tags:  
  • c#
  • Related