Application c # to insert data into a bd nsf?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Application c # to insert data into a bd nsf?

  1. #1
    Join Date
    Sep 2010
    Posts
    7

    Application c # to insert data into a bd nsf?

    I have the following problem:
    I'm trying to create an application to insert data into lotus notes nsf bases by an application of C #. So far I have this:
    private void button2_Click(object sender, EventArgs e)
    {
    bool isServerData = radioButton1.Checked;
    // Set up connection string
    string connString = ("Driver=Lotus NotesSQL Driver (*.nsf);" + ("Server=" + textBox1.Text + ";" + "Database=C:\\Archivos de programa\\Lotus\\notes\\data\\clientes\\… + "UserName = 192.168.*.*" +";" + "Password= "+ textBox2.Text + "" ));
    string CmdString = "SELECT * FROM Contactos";
    OdbcConnection Conn = null;
    OdbcDataReader Reader = null;
    OdbcDataAdapter adaptador = new OdbcDataAdapter();
    DataTable contactos;
    string con = connString;
    //string sel = ("INSERT INTO Contactos (_126, _21, _19, _20) VALUES(?, ?, ?, ?) ");
    string sel = "INSERT INTO Contactos (_126, _21, _19, _20) VALUES('Luisa', 'noexiste@nohay.com', '55555555', 'programador')";
    try
    {
    // Open Connection

    /***************************************…
    Conn = new OdbcConnection(connString);
    Conn.Open();

    // Execute Query
    OdbcCommand Cmd = new OdbcCommand(CmdString, Conn);
    adaptador = new OdbcDataAdapter(Cmd);
    contactos = new DataTable();
    adaptador.Fill(contactos);
    adaptador.SelectCommand = Cmd;
    **********************************/
    Conn = new OdbcConnection(connString);
    Conn.Open();
    OdbcCommand Cmd = new OdbcCommand(sel, Conn);
    //OdbcCommand Dmd = new OdbcCommand(sel, Conn);
    //Cmd.Parameters.AddWithValue("@_126", "Luisa");
    //Cmd.Parameters.AddWithValue("@_21", "noexiste@nohay.com");
    //Cmd.Parameters.AddWithValue("@_19", "55555555");
    //Cmd.Parameters.AddWithValue("@_20", "programador");
    //adaptador.InsertCommand = Dmd;
    ////Dmd.Dispose();
    Cmd.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
    error = (ex.Message);
    }
    finally
    {
    Conn.Close();
    }

    }
    Make the following error:
    System.Data.Odbc.OdbcException was detected
    Message="ERROR [HY000] [Lotus][ODBC Lotus Notes]No INSERT/UPDATE/ALTER/CREATE INDEX/CREATE VIEW on view"
    Source="NSQLV32.DLL"
    ErrorCode=-2146232009
    StackTrace:
    en System.Data.Odbc.OdbcConnection.HandleEr… hrHandle, RetCode retcode)
    en System.Data.Odbc.OdbcCommand.ExecuteRead… behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod)
    en System.Data.Odbc.OdbcCommand.ExecuteRead… behavior, String method, Boolean needReader)
    en System.Data.Odbc.OdbcCommand.ExecuteNonQ…
    en LOTUS.Form1.button2_Click(Object sender, EventArgs e) en D:\Respaldos\Ejemplos Devexpress y c#\LOTUS\LOTUS\Form1.cs:línea 82
    InnerException:


    Thank you very much and sorry for the inconvenience.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,198

    Re: Application c # to insert data into a bd nsf?

    The error believes that 'Contactos' is a view rather than a table. Is it?

  3. #3
    Join Date
    Sep 2010
    Posts
    7

    Re: Application c # to insert data into a bd nsf?

    Hello

    No, is the name of the table to insert the data.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,198

    Re: Application c # to insert data into a bd nsf?

    It's a bit hard to follow the code (please use code tags in the future).

    It's hard for me to tell which piece of code is causing the error.

    Can you try this code?

    Code:
    var sel = "INSERT INTO Contactos (_126, _21, _19, _20) VALUES('Luisa', 'noexiste@nohay.com', '55555555', 'programador')";
    
    try
    {
      using( var conn = new OdbcConnection(connString);
      {
        conn.Open();
    
        using( var cmd = new OdbcCommand( sel, conn ) )
        {
          cmd.ExecuteNonQuery( );
        }
    }
    catch( Exception e )
    {
      var error = e.Message;
    }
    }
    The '_' column names look a bit strange. Do the column names really start with an underscore?

  5. #5
    Join Date
    Sep 2010
    Posts
    7

    Re: Application c # to insert data into a bd nsf?

    Make the same mistake in the following line:

    cmd.ExecuteNonQuery( );

    System.Data.Odbc.OdbcException
    Message="ERROR [HY000] [Lotus][ODBC Lotus Notes]No INSERT/UPDATE/ALTER/CREATE INDEX/CREATE VIEW on view"
    Source="NSQLV32.DLL"
    ErrorCode=-2146232009
    StackTrace:
    en System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
    en System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod)
    en System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader)
    en System.Data.Odbc.OdbcCommand.ExecuteNonQuery()
    en LOTUS.Form1.button2_Click(Object sender, EventArgs e) en D:\Respaldos\Ejemplos Devexpress y c#\LOTUS\LOTUS\Form1.cs:línea 71
    InnerException:


    Thank you very much for paying attention to my problem. Nobody has been able to help =).

  6. #6
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,960

    Re: Application c # to insert data into a bd nsf?

    Code:
    on view
    Sure it's a table? Looks like a VIEW statement.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Sep 2010
    Posts
    7

    Re: Application c # to insert data into a bd nsf?

    Hello:

    Research a while and you are right is a view

  8. #8
    Join Date
    Sep 2010
    Posts
    7

    Re: Application c # to insert data into a bd nsf?

    Able to find one of the names of the tables, this brings the same data exacerbated Contacts.

    But now I check this error:

    System.Data.Odbc.OdbcException detected
    Message = "ERROR [HY000] [Lotus] [ODBC Lotus Notes] Column is Not updatable - $ 126"
    Source = "NSQLV32.DLL"
    ErrorCode =- 2146232009
    StackTrace:
    in System.Data.Odbc.OdbcConnection.HandleError (OdbcHandle hrHandle, retcode retcode)
    in System.Data.Odbc.OdbcCommand.ExecuteReaderObject (CommandBehavior Behavior, String method, Boolean needReader, Object [] methodArguments, SQL_API odbcApiMethod)
    in System.Data.Odbc.OdbcCommand.ExecuteReaderObject (CommandBehavior Behavior, String method, Boolean needReader)
    in System.Data.Odbc.OdbcCommand.ExecuteNonQuery ()
    in LOTUS.Form1.button2_Click (Object sender, EventArgs e)
    InnerException:

    Sorry so much trouble, but is that databases do not know anything * nsf

  9. #9
    Join Date
    Sep 2010
    Posts
    7

    Re: Application c # to insert data into a bd nsf?

    Thank you very much, with your help I knew it was just a view, but as it had something to manage the content of the nsf databases did not know where he was going to add so I guess.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center