0

私はasp.netコードを書くことにかなり慣れていないので、問題を解決できません。登録しようとするたびに、次のエラーが表示されます。

Type name is invalid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Type name is invalid.

Source Error:

Line 60:             }
Line 61: 
Line 62:             cmnd.ExecuteNonQuery();
Line 63:             this.cnct.Close();
Line 64:         }

ソースコードは次のとおりです。

    public class Connection
    {
        private OleDbConnection cnct;

        public Connection(string dbPath)
        {
            this.cnct = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + dbPath);
        }

        /// <param name="types">'c' - VarChar, 'C' - Char, 'n' - VarNumeric, 'b' - Boolean</param>
        public void Insert(string tableName, string[] inputs, char[] types)
        {
            string sql = "INSERT INTO " + tableName + " VALUES (";
            for (int i = 0; i < inputs.Length - 1; i++)
                sql += "@p" + i + ",";
            sql += "@p" + (inputs.Length - 1) + ")";

            this.cnct.Open();
            OleDbCommand cmnd = new OleDbCommand(sql, this.cnct);

            for (int i = 0; i < inputs.Length; i++)
            {
                if (types[i] == 'c')
                {
                    cmnd.Parameters.Add("@p" + i, OleDbType.VarChar);
                    cmnd.Parameters["@p" + i].Value = inputs[i];
                }
                else if (types[i] == 'C')
                {
                    cmnd.Parameters.Add("@p" + i, OleDbType.Char);
                    cmnd.Parameters["@p" + i].Value = inputs[i];
                }
                else if (types[i] == 'n')
                {
                    cmnd.Parameters.Add("@p" + i, OleDbType.VarNumeric);
                    cmnd.Parameters["@p" + i].Value = double.Parse(inputs[i]);
                }
                else if (types[i] == 'b')
                {
                    cmnd.Parameters.Add("@p" + i, OleDbType.Boolean);
                    cmnd.Parameters["@p" + i].Value = bool.Parse(inputs[i]);
                }
            }

            cmnd.ExecuteNonQuery();
            this.cnct.Close();
        }
    }

Insert メソッドは次を使用して呼び出されます。

Connection cnct = new Connection(Server.MapPath("App_Data/WMUdb.mdb"));
cnct.Insert("members", values, new char[7] { 'c', 'c', 'c', 'c', 'C', 'n', 'b' });

(どこ

values = new string[7] {"userName","my name","pswrd123","email@example.com","2000-01-01"};

)。

それを解決するにはどうすればよいですか?

どうもありがとう。

4

2 に答える 2

2

Jet エンジン用の OLEDB プロバイダーは をサポートしていないようOleDbType.VarNumericです。

OleDbType.Numeric代わりに使用してみてください。

于 2011-02-22T13:01:26.143 に答える
0

さらに、日付列の匂いがします... "2000-01-01"}; テーブルの列のデータ型が期待どおりの文字であるか、実際には日付/時刻の列であるかを確認してください。その場合は、パラメータタイプがDateTimeであり、問​​題の2000-01-01日付の12:00:00 amに設定されている場合でも、パラメータ値を日付/時刻値として適切に設定していることを確認してください。

于 2011-02-22T16:04:32.157 に答える