该字符串未被识别为有效时间错误 [英] The string was not recognised as a valid time error

查看:92
本文介绍了该字符串未被识别为有效时间错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谢谢大家。

我希望使用下面的代码进行搜索,但我的代码生成错误没有记录:字符串未被识别为有效时间。从索引处开始有一个未知单词0。我将不胜感激任何帮助



我的尝试:



Thank you guys.
I wish to search using the code below but my code generated error " No Record: The string was not recognised as a Valid Time. There is an unknown word starting at index 0." I will appreciate any assistance

What I have tried:

private void btnSearch_Click(object sender, EventArgs e)
        {

           if (textBox1.Text == "")
            { }
            else
            {
                FileStream fs = new FileStream(textBox1.Text, FileMode.OpenOrCreate, FileAccess.Read);
                byte[] bt = new byte[fs.Length];
                fs.Read(bt, 0, System.Convert.ToInt32(fs.Length));
                fs.Close();
                SqlConnection con = new SqlConnection();
                con.ConnectionString = "Data Source=AKINTOMIDE-HP\\SQLEXPRESS;Initial Catalog=fham;Integrated Security=True";
                cmd = new SqlCommand("select * from master where eid =@eid", con);
                con.Open();
                cmd.Parameters.AddWithValue("@eid", txteid.Text);
                cmd.Connection = con;
                try
                {
                    dreader = cmd.ExecuteReader();
                    if (dreader.Read())
                    {
                        //txtname.Text = dreader[1].ToString(); 
                        txteid.Text = dreader[1].ToString();
                        cmbYr.Text = dreader[2].ToString();
                        datAd.Text = dreader[3].ToString();
                        datEmp.Text = dreader[4].ToString();
                        DatMod.Text = dreader[5].ToString();
                        txtStaf.Text = dreader[6].ToString();
                        txtAdrs.Text = dreader[7].ToString();
                        txtCoy.Text = dreader[8].ToString();
                        cmbDpt.Text = dreader[9].ToString();
                        cmbLoc.Text = dreader[10].ToString();
                        CmbGrd.Text = dreader[11].ToString();
                        TxtAccno.Text = dreader[12].ToString();
                        txtemail.Text = dreader[13].ToString();
                        // bt=dreader[14].ToString();
                        cmbBank.Text = dreader[15].ToString();
                        cmbPenAdmin.Text = dreader[16].ToString();
                        cmbStatus.Text = dreader[17].ToString();
                        txtPenNum.Text = dreader[18].ToString();
                        txtBSal.Text = dreader[19].ToString();
                        txtDres.Text = dreader[20].ToString();
                        txtDUpfront.Text = dreader[21].ToString();
                        txtEduc.Text = dreader[22].ToString();
                        txtFurn.Text = dreader[23].ToString();
                        txtHarz.Text = dreader[24].ToString();
                        txtTran.Text = dreader[25].ToString();
                        txtHous.Text = dreader[26].ToString();
                        txtLunc.Text = dreader[27].ToString();
                        txtUti.Text = dreader[28].ToString();
                        txtHousM.Text = dreader[29].ToString();
                        txtRisk.Text = dreader[30].ToString();
                        txtVeh.Text = dreader[31].ToString();
                        txtPfS.Text = dreader[32].ToString();
                        txtNHF.Text = dreader[33].ToString();
                        txtNHFS.Text = dreader[34].ToString();
                        txtOded.Text = dreader[35].ToString();
                        txtPens.Text = dreader[36].ToString();
                        txtPAYE.Text = dreader[37].ToString();
                        txtTDed.Text = dreader[38].ToString();
                        txtDriv.Text = dreader[39].ToString();
                        txtDome.Text = dreader[40].ToString();
                        txtTPay.Text = dreader[41].ToString();
                        txtNPay.Text = dreader[42].ToString();
                        txtHousU.Text = dreader[43].ToString();
                        txtStaffM.Text = dreader[44].ToString();
                        txtThrift.Text = dreader[45].ToString();
                        cmbMon.Text = dreader[46].ToString();
                        txtOtherPay.Text = dreader[47].ToString();
                        textBox1.Text = dreader[48].ToString();
                        button1.Text = dreader[49].ToString();                            ClearData();
                    }
                    else
                    {
                        MessageBox.Show(" No Record");
                    }
                    dreader.Close();
                }
                catch (Exception x)
                {
                    MessageBox.Show("No Record:\n" + x.Message);
                }
                finally
                {
                    con.Close();
                }
            }

        }

推荐答案

我们不能:我们有无法访问代码在运行时或您的数据。

所以,它取决于你。

在函数的第一行放置一个断点,并通过调试器运行您的代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一种新的(非常非常有用的)技能:调试!
We can't: we have no access to your code while it is running, or your data.
So, its going to be up to you.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!


只需备份@OriginalGriff所说的内容解决方案1 ​​ - 这是一篇CodeProject文章,可以帮助您成为专家调试器...... 掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]
Just backing up what @OriginalGriff has said in Solution 1 - here is a CodeProject article to help you along the way to becoming an expert debugger ... Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]


这篇关于该字符串未被识别为有效时间错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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