I was asked how to create a table ID using C++ & .NET – I thought it was a worth while thing to post here. Not really that different from the post I made a while back about creating an ID in C#, just a few syntactical changes and voíla!
OleDbConnection* conn = new OleDbConnection(_connstring);
try
{
conn->Open();
OleDbCommand* cmd = new OleDbCommand("slx_dbids('account', 1)", conn);
// place new ID in a textbox
textBox1->Text = cmd->ExecuteScalar()->ToString();
}
catch (char* ex)
{
MessageBox::Show(ex);
}
conn->Dispose();
One thing to note here is that the connection string must be via the SalesLogix provider (See Understanding the SalesLogix OLEDB Connection String)




Sure that will work, but I’d recommend only using that in cases where you are returning more than one ID value (ie: the second parameter). No need for the added overhead of the datareader for just returning a single ID value. In case of a scalar return, use something geared for just that, which is of course what the ExecuteScalar method of the command is for. Not only that but you’re relying on the calling code to close the datareader (and therefore the connection as well). Know what I mean?