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
In this sample you've called String.Format
with a string containing place holders {0}
but provided no arguments. You need to either remove the place holders or provide an argument to fill in the {0}
slot
If you want to literally put {0}
into the string then don't use String.Format
or properly escape them via {{0}}
.
You're calling string.Format
including {0}
in various places, indicating that you want a placeholder to be replaced... but you're not providing the placeholder value.
You want something like:
tableCreateCommand.CommandText = string.Format("...", checkNumber);
However, I suspect you actually want multiple parameters ({0}
, {1}
, {2}
etc) rather than just one. What SQL are you expecting from the result of string.Format
?
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)", <you need to specify
the list of values for place holders here...>)
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)
You haven't passed a string to string.Format that it needs to place into your {0} place-holder. Are you missing a variable?
...string.Format("your long format string {0}", someMissingStringVar);