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

前端 未结 4 1438
南方客
南方客 2021-01-26 10:32

I am trying to create a new table in a database which has a name of checkout and a check number which ive put in {0}. But when I run the program it comes up with the error shown

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-26 10:57

    You haven't specified any values for the placeholders in String.Format.

    string.Format("create table Checkout{0} (ID int, Productlist varchar{0}, 
    Date varchar {0}, Time varchar (50), Total double)",  )
    

    It should be something like this. Note the values specified from second parameter onwards. You can use a constant or some variable in place of constants shown here. The value specified after the comma will replace the placeholders in the index order. {0} will use value 123456, {1} would use 50, {2} would use 65 and {3} would use 75.

    string.Format("create table Checkout{0} (ID int, Productlist varchar({1}), 
    Date varchar({2}), Time varchar ({3}), Total double)", 123456, 50, 65, 75)
    

    If you need to use the same placeholder for varchar as specified for checkout, it should be like this. I am not sure if this is your intention. Here all place holders {0} will use the same value 100.

    string.Format("create table Checkout{0} (ID int, Productlist varchar({0}), 
    Date varchar({0}), Time varchar (50), Total double)", 100)
    

提交回复
热议问题