我有一个SQLSqlCeParameter语句,例如:
SqlCeParameter
mySQLCommand1.CommandText = @" INSERT INTO clientSubjectiveComplaints (clientSubComplaintCreated) VALUES (@ClientSubComplaintCreated) ";
一旦INSERT成功,我需要返回自动生成的ID(INT主键),以便可以在第二条INSERT语句中使用它。
INSERT
这可能SqlCe吗?请提供一个例子。
SqlCe
像这样:
using (var connection = new SqlCeConnection(Settings.Default.Database1ConnectionString)) using (var command = connection.CreateCommand()) { connection.Open(); command.CommandText = @" INSERT Test (Name) VALUES (@TestName) "; command.Parameters.AddWithValue("TestName", "SomeName"); command.ExecuteNonQuery(); command.CommandText = "SELECT @@IDENTITY"; var id = command.ExecuteScalar(); }