none
ResultSet Question - NOOB RRS feed

  • Question

  • VS2008, C#, Windows Mobile Smart Device Application

    I'm trying to work my way through learning how to best use DataSets and ResultSets in my applications (making the transition from VB6 --> .Net) and have a question. Also very new to OO dev.

    I have created a test application, a WindowsMobile project using C#, as a tool to learn with. I added a database (AppDatabase) to the application in which I created a single table (tblData). This table has three fields; ID (bigint, identity, autoincrements), DateTime (datetime, autassigns to GetDate()), and Information (nvarchar(100)).

    I next added a Data Source to the project referencing the database/table above, which generated appropriate data set objects within my solution.

    Next I changed the Custom Tool of the Data Source from MSDataSetGenerator to MSDataSetResultSetGenerator, which then generated the appropriate Result Set object (tblDataResultSet).

    What I am attempting to do is this. I would like to programmatically make a table insert. Withing my code I first added the following to create an instance of this:

    SDDataTest.AppDatabaseResultSets.

    tblDataResultSet rs = new SDDataTest.AppDatabaseResultSets.tblDataResultSet();

    Then, I thought to use the generated AddtblDataRecord() method to perform my insert. This method is prompting for the three fields in the table, only one of which I actually want to insert (the other two; ID nad DateTime are automatically filled).

    At first I thought to modify the generated code for AddtblDataRecord to omit these two fields but then promptly noted that this method was regenerated when I re ran the custom tool on the data source.

    So now for my questions. What is the appropriate and accepted way to handle this? Is a result set the appropriate way to go about this or should I look at something else?

    Thanks!


    Gary in Massena. WinForms Client Development. SQL Server Management and Development.
    Thursday, August 26, 2010 5:44 PM

Answers

  • Hi GTNovosel,

     

    First, you should not modify the auto-generated code. Changes to that may cause incorrect behavior and will be lost if the code is regenerated. Second, did you set ID column as the primary key ? If you did not, the ID column will also been shown in the parameter of AddtblDataRecord() method and if you set the DefaultValue of the DateTime column to (getdate()) and you did not assign a value for it, the (getdate()) funtion will be called to genarate the date for that column which you do not need to worry about.

    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, August 27, 2010 9:21 AM
    Moderator
  • Hi GTNovosel,

     

    Sorry for the late reply.

     

    I do not think you can make use of the auto generated code like that, but you can add a partial class for and add a method like AddtblDataRecord() with "TicketNo" as the only parameter, something like: 

     

    namespace SmartDeviceProject2.AppDatabase1ResultSets
    {
     public partial class tblTestResultSet : System.Data.SqlServerCe.SqlCeResultSet
     {
     public void AddtblTestRecord(int TicketNo)
     {
      System.Data.SqlServerCe.SqlCeUpdatableRecord newRecord = base.CreateRecord();
      newRecord["TicketNo"] = TicketNo;
      base.Insert(newRecord);
     }
     }
    }
    
    


    Best regards,
    Alex Liang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

     

    Monday, September 13, 2010 6:26 AM
    Moderator

All replies

  • Hi GTNovosel,

     

    First, you should not modify the auto-generated code. Changes to that may cause incorrect behavior and will be lost if the code is regenerated. Second, did you set ID column as the primary key ? If you did not, the ID column will also been shown in the parameter of AddtblDataRecord() method and if you set the DefaultValue of the DateTime column to (getdate()) and you did not assign a value for it, the (getdate()) funtion will be called to genarate the date for that column which you do not need to worry about.

    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, August 27, 2010 9:21 AM
    Moderator
  • Hi GTNovosel, 

    I'm writing to follow up the post. Does the above suggestion work ?

    Please feel free to let me know if you need any help.

    Best regards,
    Alex Liang

    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, September 2, 2010 9:55 AM
    Moderator
  • Alex,

    Sorry, I haven't had a chance to get back to this project yet to try your suggestion.

    Without trying it yet, I do have a follow up question. Assuming the following simple table structure for a header record to an issue tracking system.

    CREATE TABLE [dbo].[tblTest](
    	[ID] [bigint] IDENTITY(1,1) NOT NULL,
    	[dtCreated] [datetime] NOT NULL CONSTRAINT [DF_tblTest_dtCreated] DEFAULT (getdate()),
    	[TicketNo] [int] NOT NULL,
    	[dtStart] [datetime] NULL,
    	[dtComplete] [datetime] NULL
    

    The first two fields are simply handled by SQL. For the initial insert I'd want to specify the TicketNo only. Then an update to dtStart when work is started. And finally an update to dtComplete when the work is done.

    How can I make use of the auto generated code to handle these three actions on a record in this table?


    Gary in Massena. WinForms Client Development. SQL Server Management and Development.
    Thursday, September 2, 2010 1:13 PM
  • Hi GTNovosel,

     

    Sorry for the late reply.

     

    I do not think you can make use of the auto generated code like that, but you can add a partial class for and add a method like AddtblDataRecord() with "TicketNo" as the only parameter, something like: 

     

    namespace SmartDeviceProject2.AppDatabase1ResultSets
    {
     public partial class tblTestResultSet : System.Data.SqlServerCe.SqlCeResultSet
     {
     public void AddtblTestRecord(int TicketNo)
     {
      System.Data.SqlServerCe.SqlCeUpdatableRecord newRecord = base.CreateRecord();
      newRecord["TicketNo"] = TicketNo;
      base.Insert(newRecord);
     }
     }
    }
    
    


    Best regards,
    Alex Liang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

     

    Monday, September 13, 2010 6:26 AM
    Moderator
  • Hi GTNovosel, 

    I'm writing to follow up the post. Does the above suggestion work ?

    Please feel free to let me know if you need any help.

    Best regards,
    Alex Liang

    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, September 16, 2010 9:24 AM
    Moderator
  • Hi GTNovosel, 

    I'm marking the reply as answer. Please feel free to let me know if you need any help.

    Best regards,
    Alex Liang

    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, September 27, 2010 5:48 AM
    Moderator