Link to home
Start Free TrialLog in
Avatar of flynny
flynnyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Return inserted ID from MSSQL insert and TableAdapters

Hi all I have the following code for a paypal ipn handler;

            int raw_ipn_id = -1;

            try
            {
                using (raw_logTableAdapter rawTable = new raw_logTableAdapter())
                {
                    raw_ipn_id = (int)rawTable.InsertRawIPN(strResponse_copy);
                }
            }
            catch(Exception ex)
            {
                Global.log.Error(String.Format("Error:IPNHandler.aspx.cs: Exception generated inserting to raw_log table :{0}:", ex.Message));
            }

Open in new window


now the InsertRawIPN SQL code in the tableadapter is as follows;

INSERT INTO [raw_log] ([ipn_data_serialized]) VALUES (@ipn_data_serialized);

Open in new window


I have set the Execute mode to Scalar, however I am getting the following error;

Error:IPNHandler.aspx.cs: Exception generated inserting to raw_log table :Object reference not set to an instance of an object.:

So it appears to not be returning the identity?

1. Do I need to specifiy the return in the SQL code?

2. Also when inserting I would like to insert the current timestamp to another variable, can i do this in the table adapter SQL code? Coul dsomeone provide an example for me please?

Thanks in advance,

Matt.
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of flynny

ASKER

sorry its been a long day.
No prob.  Thanks for the grade.  Good luck with your project.  -Jim