1 Replies - 2058 Views - Last Post: 27 April 2011 - 07:27 PM Rate Topic: -----

#1 keiri   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-August 09

exception of type 'System.Data.OleDb.OleDbException' occurred

Posted 27 April 2011 - 07:16 PM

        public void addProduct(string title, string author, string publisher, string date,
         string summary, string binding, string genre, string price, int quantity) {

            try {

                conn.Open();
                OleDbTransaction trans;
                trans = conn.BeginTransaction();
                OleDbCommand odbcmd; ;
 

                Console.WriteLine(title);
                Console.WriteLine(author);
                Console.WriteLine(publisher);
                Console.WriteLine(date);
                Console.WriteLine(summary);
                Console.WriteLine(binding);
                Console.WriteLine(genre);
                Console.WriteLine(price);
                Console.WriteLine(quantity);

                odbcmd = new OleDbCommand("INSERT INTO PRODUCTS VALUES(?,?,?,?,?,?,?,?,?)", conn);

                odbcmd.Transaction = trans; 
                odbcmd.Parameters.Add("title", OleDbType.VarChar).Value = title;
                odbcmd.Parameters.Add("author", OleDbType.VarChar).Value = author;
                odbcmd.Parameters.Add("publisher", OleDbType.VarChar).Value = publisher;
                odbcmd.Parameters.Add("date", OleDbType.VarChar).Value = date;
                odbcmd.Parameters.Add("summary", OleDbType.VarChar).Value = summary;
                odbcmd.Parameters.Add("binding", OleDbType.VarChar).Value = binding;
                odbcmd.Parameters.Add("genre", OleDbType.VarChar).Value = genre;
                odbcmd.Parameters.Add("price", OleDbType.VarChar).Value = price;
                odbcmd.Parameters.Add("quantity", OleDbType.Integer).Value = quantity;
                
                odbcmd.ExecuteNonQuery();
                Console.WriteLine("data Inserted...");
                trans.Commit();
            } catch (Exception ex) {
                Console.WriteLine(ex.StackTrace);
            } finally {
                conn.Close();
            }
        }


i get this error,
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(Commandbehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(Commandbehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at ServerApp.Server.addProduct(String title, String author, String publisher, String date, String summary, String binding, String genre, String price, Int32 quantity) in E:\MACHINE PROJ\ServerApp\ServerApp\Server.cs:line 119




what should i do??? thanks

This post has been edited by keiri: 27 April 2011 - 07:17 PM


Is This A Good Question/Topic? 0
  • +

Replies To: exception of type 'System.Data.OleDb.OleDbException' occurred

#2 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: exception of type 'System.Data.OleDb.OleDbException' occurred

Posted 27 April 2011 - 07:27 PM

You need to use ex.Message along with ex.StackTrace in the error message. The Message is the actual error message. The StackTrace is used to track where the error occurred in the code.

So we need to know the ACTUAL error that occurred.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1