- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用此代码在某些标签中使用 C# 显示 MySQL 数据库中的数据,但它一直告诉我我指定了无效的列序号
private void store_Load(object sender, EventArgs e)
{
string constring = "datasource=localhost;port=3306;username=root";
string Query = "select Value from birth.store;";
MySqlConnection c = new MySqlConnection(constring);
MySqlCommand cmd = new MySqlCommand(Query, c);
MySqlDataReader reader;
try
{
c.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
label3.Text = reader.GetInt32(1).ToString();
label4.Text = reader.GetInt64(0).ToString();
label6.Text = reader.GetInt64(8).ToString();
label10.Text = reader.GetInt64(5).ToString();
label14.Text = reader.GetInt64(7).ToString();
label13.Text = reader.GetInt64(13).ToString();
label11.Text = reader.GetInt64(10).ToString();
label20.Text = reader.GetInt64(12).ToString();
label19.Text = reader.GetInt64(16).ToString();
label17.Text = reader.GetInt64(14).ToString();
label26.Text = reader.GetInt64(15).ToString();
label32.Text = reader.GetInt64(4).ToString();
label31.Text = reader.GetInt64(6).ToString();
label23.Text = reader.GetInt64(3).ToString();
label27.Text = reader.GetInt64(2).ToString();
label25.Text = reader.GetInt64(11).ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
最佳答案
您向 GetInt32()
传递的数字对于查询中的列数而言太大。您传递给 reader.GetInt32()
或 reader.GetInt64()
的索引是查询中 SELECT 语句中该列的位置,从 0 开始。查询如下所示:
string Query = "select Value from birth.store;";
只有一列(SELECT
和 FROM
之间的名称),因此任何大于 0 的数字如果传递给 reader.GetInt32() 都是无效的。查询中的列越多,可以传递的数字就越大。
1 列示例:
string Query = "select Value from birth.store;";
// database connection and reader execution go here
string Value = reader.GetInt32(0).toString(); // This gets the column Value
3 列示例:
// We're selecting 3 columns now
// 0 = Id
// 1 = Value
// 2 = Name
string Query = "select Id, Value, Name from birth.store;";
// database connection and reader execution go here
string Value = reader.GetInt32(1).toString(); // This gets the column Value
// This gets the column Id. Even though it's not the first one we pulled from
// the reader, it's still #0 on the list of 3 columns.
string Id = reader.GetInt32(0).toString();
string Name = reader.GetInt32(2).toString(); // This gets the column Name
// This will throw an exception. You're trying to get the 4th item on a list
// that starts with 0, but there are only 3 items (numbered 0, 1, 2).
string AnotherValue = reader.GetInt32(3).toString();
关于c# - 您在 mysql 中使用 c# 指定了无效的列序数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30135140/
我需要定义 format为 date我的索引中的字段 { "mappings": { "properties": { "date": { "type": "da
我需要找到整数数组中元素的降序。 例子: 如果我有一个数组: x = {24, 55, 22, 1} 我想要一个 C 中的算法,它导致数组 order 其中: order = {2, 1, 3, 4}
我正在尝试用 Java 确定一个月中某个工作日的连续序号。即如果星期五是一个月的第一个或第三个星期五。 在阅读了我在 Java 日历上可以找到的所有内容和此处的帖子后,我找不到简单的方法。我能想到的一
我有一个关于 ordinal 的问题包裹在 R或者特别是关于 predict.clm()功能。我想计算linear predictor的 ordered probit估计。使用 MASS 包的 pol
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有一个 D3 分组条形图,其中 x 轴使用我的 x0 比例形成,其中域作为数据值。由于域具有数据值,我的刻度文本也是相同的数据值。我想将刻度值更改为数据名称,保持比例不变,因为名称可以相同,但数据值
有没有办法使用 NSNumberFormatter 来获取 'th' 'st' 'nd' 'rd' 数字结尾? 编辑: 看起来它不存在。这是我正在使用的。 +(NSString*)ordinalNum
我想根据当天动态生成一串文本。因此,例如,如果是第 1 天,那么我希望我的代码生成 = "Its the 1*st*". 总共有 12 天,所以我做了以下事情: 我设置了一个循环 12 天的 for
ruby 或 rails 中是否有任何东西可以处理序数的格式:'1' 为 '1st','2' 为 '2nd',等等? 最佳答案 看起来你正在寻找序号: The Ruby on Rails framew
我是一名优秀的程序员,十分优秀!