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', '[email protected]', '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", "[email protected]");
//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.
Re: Application c # to insert data into a bd nsf?
The error believes that 'Contactos' is a view rather than a table. Is it?
Re: Application c # to insert data into a bd nsf?
Hello
No, is the name of the table to insert the data.
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', '[email protected]', '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?
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 =).
Re: Application c # to insert data into a bd nsf?
Sure it's a table? Looks like a VIEW statement.
Re: Application c # to insert data into a bd nsf?
Hello:
Research a while and you are right is a view
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
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.