ASP.NET ODBC Query with parameters

前端 未结 4 871
醉话见心
醉话见心 2020-12-01 19:46

Please help me, I don\'t know what can be wrong with the following code:

        OdbcConnection conn = new OdbcConnection(connString);
        String query =         


        
相关标签:
4条回答
  • 2020-12-01 20:05

    From MSDN:

    When CommandType is set to Text, the .NET Framework Data Provider for ODBC does not support passing named parameters to an SQL statement or to a stored procedure called by an OdbcCommand. In either of these cases, use the question mark (?) placeholder. For example:

    SELECT * FROM Customers WHERE CustomerID = ?
    

    Rewrite your query to

    OdbcConnection conn = new OdbcConnection(connString);
        String query = "INSERT INTO customer (custId, custName, custPass, "+
                       "custEmail, custAddress, custAge) VALUES (" +
                       "?, ?, ?, ?, ?, ?)";
    

    Order of Parameter counts!

    EDIT: Parameter can be added this way:

    OdbcCommand exe = new OdbcCommand(query, conn);
    exe.Parameters.Add("ID", OdbcType.UniqueIdentifier).Value = id;
    exe.Parameters.Add("Name", OdbcType.VarChar).Value = name;
    exe.Parameters.Add("Pass", OdbcType.VarChar).Value = pass;
    exe.Parameters.Add("Email", OdbcType.VarChar).Value = email;
    exe.Parameters.Add("Address", OdbcType.VarChar).Value = address;
    exe.Parameters.Add("Age", OdbcType.Int).Value = age;
    
    0 讨论(0)
  • 2020-12-01 20:10

    One of your columns in your query does not exist.
    Please check your column names.

    0 讨论(0)
  • 2020-12-01 20:20

    Typically you'll see this when you misspell a column name in your SQL statement. Are you sure of those column names (custId, custName, etc.)?

    0 讨论(0)
  • 2020-12-01 20:24

    try changing pass to passw maybe it is getting mixed up with asp identifier...

    0 讨论(0)
提交回复
热议问题