索引(基于零)必须大于参数列表的大小大于或等于零且小于 [英] Index (zero based) must be greater than or equal to zero and less than the size of the argument list

查看:5727
本文介绍了索引(基于零)必须大于参数列表的大小大于或等于零且小于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想其中有结账的名称和香港专业教育学院放在{0}支票号码的数据库中创建一个新表。但是,当我运行程序它在标题所示的错误的出现产品列表VARCHAR(50)

  SQLiteCommand tableCreateCommand = myConnection.CreateCommand(); 
tableCreateCommand.CommandText =的String.Format(创建表结账{0}(ID INT,VARCHAR产品列表{0},日期为varchar {0},时间为varchar(50),道达尔双));
tableCreateCommand.ExecuteNonQuery();


解决方案

您还没有指定任何值在占位符的String.Format。

 的String.Format(创建表结账{0}(ID INT,VARCHAR产品列表{0},
日期VARCHAR {0},时间为varchar(50),道达尔双),<您需要指定
为占位这里值的列表...>)

应该是这样的。注意从第二个参数开始指定的值。您可以在这里举行显示常量使用常量或某些变量。逗号后指定的值将替换索引顺序中的占位符。 {0} 将使用值 123456 {1} 会使用 50 {2} 会使用 65 {3} 将使用 75

 的String.Format(创建表结账{0}(ID INT,VARCHAR产品列表({1}),
日期为varchar({2}),时间为varchar({3}),道达尔双),123456,50,65,75)

如果您需要作为结账指定使用相同的占位符VARCHAR,它应该是这个样子。我不知道,如果这是你的意图。在这里,所有的占位符{0}将使用相同​​的值100。

 的String.Format(创建表结账{0}( ID INT,产品列表VARCHAR({0}),
日期为varchar({0}),时间为varchar(50),道达尔双),100)


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 the title for the "Productlist varchar(50)"

SQLiteCommand tableCreateCommand = myConnection.CreateCommand();
tableCreateCommand.CommandText = string.Format("create table Checkout{0} (ID int, Productlist varchar{0}, Date varchar {0}, Time varchar (50), Total double)");
tableCreateCommand.ExecuteNonQuery();

解决方案

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)

这篇关于索引(基于零)必须大于参数列表的大小大于或等于零且小于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆