Hi,
I have been looking for away to get an output variable from an SQL query, however for SQL Compact Edition.
using (da.InsertCommand = new SqlCeCommand(@"INSERT INTO SCHEMAS (SCHEMA_NAME, FromMethod, ToMethod, ConnectedToUserID) OUTPUT INSERTED.SCHEMA_ID
VALUES (@SchemaName, @FromMethod, @ToMethod, @ConnectedToUserID)", connString))
{
da.InsertCommand.Parameters.AddWithValue("@SchemaName", textBoxSchemaName.Text);
da.InsertCommand.Parameters.AddWithValue("@FromMethod", comboBoxFromMethod.Text);
da.InsertCommand.Parameters.AddWithValue("@ToMethod", comboBoxToMethod.Text);
da.InsertCommand.Parameters.AddWithValue("@ConnectedToUserID", userID);
da.InsertCommand.Connection.Open(); //Needed to open a connection
da.InsertCommand.ExecuteNonQuery(); //Performs the actual SQL statement
this.Close();
}
Can someone please assist my how I can get this output variable out to a C# variable?
Thanks in advance,
Tomas
Get an OUTPUT variable from an Insert SQL statement
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Suthish NairRank #92 · 22.8K reputationPosted Nov 24, 2012, 12:23 PM EST
Tomas Westerlund38 reputationPosted Nov 24, 2012, 12:36 PM EST
thanks for your help. I solved it already like this:
Best regards,
Tomas