none
C# asp.net code 問題 RRS feed

  • 問題

  •  

    Code problem: 

    一開始我是可以運行的,之後再運行就出現這個問題 怎樣解決??

    OleDbConnection connection = new OleDbConnection();
                    connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sim\Desktop\Web.accdb";
                    connection.Open();
                    OleDbCommand command = new OleDbCommand();
                    command.Connection = connection;
                    command.CommandText = "select * from [Registration] where [Name] ='" + TextBox2.Text + "' ;";

                    OleDbDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {


                       string Number = reader.GetString(reader.GetOrdinal("Number"));
                       TextBox1.Text = Number;
                        string Name = reader.GetString(reader.GetOrdinal("Name"));
                        TextBox2.Text = Name;
                        string HKID = reader.GetString(reader.GetOrdinal("HKID"));
                        TextBox3.Text = HKID;

    Error: 

    ErrorSystem.IndexOutOFRangeException:Number

    於System.Data.ProviderBase.FieldNameLookup.GetOrdinal(StringfieldName)

    於System.Data.OleDb.OleDbDataReader.GetOrdinal(String name)

    於FYP.CS_read_database.Button2_Click(Object sender ,EventArgs e)

    2015年4月19日 上午 08:13

所有回覆