分割datetime字段时索引超出范围 [英] Index was out of range while splitting the datetime fields

查看:89
本文介绍了分割datetime字段时索引超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何编程接受空白值  datetime columns  into 网格和 代码行i ' 得到错误:

dataGridView1.Rows [RowCount - 1] .Cells [cmbIdentity.Text] .Value - Now i '
得到索引 out <范围./ / pre>



  for  int  RowCount =  1 ; RowCount <  = strfile.Length  -   1 ; RowCount ++)
{
if (strfile [RowCount] .ToString()!=
{
if (RowCount!= 0
{
string [] column = strfile [RowCount] .Split(' þ');
for int i = 1 ; i < column.Length - 1 ; i ++)
{
if (cmbColumnCombo.SelectedIndex ==((i - 1 )/ 2 ))
{
if (!string.IsNullOrEmpty(column [i])&& column [i] .ToString()!= \ u0014
{

dataGridView1.Rows.Add();

DateTime Time = Convert.ToDateTime(column [i] .ToString());
dataGridView1.Rows [RowCount - 1 ]。Cells [txtColumnName.Text.Replace( )]。值= Time.ToString( HH:mm:ss);
dataGridView1.Rows [RowCount - 1 ]。Cells [cmbColumnCombo.Text] .Value = Time.ToString( dd / MM / yyyy);
// dataGridView1.Rows [RowCount - 1] .Cells [cmbColumn1.Text] .Value + = column [i] .ToString();

}
}
}

for int i = 1 ; i < ; column.Length - 1 ; i ++)
{
if (cmbIdentity.SelectedIndex ==((i - 1 )/ 2 ))
{
if (!string.IsNullOrEmpty(column [i])&& column [i] .ToString()!= \ u0014
{
dataGridView1.Rows [RowCount - 1 ]。Cells [cmbIdentity。文字] .Value + = column [i] .ToString();
}
}
}
}
}
}





任何人都可以帮助我如何实现这个





我尝试了什么:



我更改了代码并建议为此提出新问题。

解决方案

这将取决于你正在处理的数据,我们无法为你解决这个问题。

所以从调试器开始。在失败的行上放置断点,然后运行您的应用程序。当它到达断点时,它将停止并让你控制。

您可以查看变量,如果需要更改它们,甚至重写代码并继续!

因此,请查看各种索引的确切内容,并将其与您正在访问的表进行比较。当你找到一个不适合的索引时,你就可以开始查看原因。
但我们不能为你做任何事情!


Hi,

How to program to accept a blank values for datetime columns into the grid and below is the line of code i'm getting error:

dataGridView1.Rows[RowCount - 1].Cells[cmbIdentity.Text].Value - Now i'm getting Index value is out of range.



for (int RowCount = 1; RowCount <= strfile.Length - 1; RowCount++)
            {
                if (strfile[RowCount].ToString() != "")
                {
                    if (RowCount != 0)
                    {
                        string[] column = strfile[RowCount].Split('þ');
                        for (int i = 1; i < column.Length - 1; i++)
                        {
                            if (cmbColumnCombo.SelectedIndex == ((i - 1) / 2))
                            {
                                if (!string.IsNullOrEmpty(column[i]) && column[i].ToString() != "\u0014")
                                    {
                                        
                                        dataGridView1.Rows.Add();
                                        
                                        DateTime Time = Convert.ToDateTime(column[i].ToString());
                                        dataGridView1.Rows[RowCount - 1].Cells[txtColumnName.Text.Replace(" ", "")].Value = Time.ToString("HH:mm:ss");
                                        dataGridView1.Rows[RowCount - 1].Cells[cmbColumnCombo.Text].Value = Time.ToString("dd/MM/yyyy");
                                        //dataGridView1.Rows[RowCount - 1].Cells[cmbColumn1.Text].Value += column[i].ToString();

                                }
                            }
                        }
 
                        for (int i = 1; i < column.Length - 1; i++)
                        {
                            if (cmbIdentity.SelectedIndex == ((i - 1) / 2))
                            {
                                if (!string.IsNullOrEmpty(column[i]) && column[i].ToString() != "\u0014")
                                {
                                    dataGridView1.Rows[RowCount - 1].Cells[cmbIdentity.Text].Value += column[i].ToString();
                                }
                            }
                        }
                    }
                }
            }



Can anyone please help me how to achieve this?



What I have tried:

I have changed the code and suggested to raise a new question for this.

解决方案

This is going to depend so much on the data you are processing that we can't fix it for you.
So start with the debugger. Put a breakpoint on the line that fails, and run your app. When it reaches the breakpoint, it will stop and let you take control.
You can look at variables, change them if you need to, even rewrite your code and continue!
So look at what your various indexes are exactly, and compare that to the tables you are accessing. When you find an index that doesn't fit, you can then start to look at why.
But we can't do any of that for you!


这篇关于分割datetime字段时索引超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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