DataGrid and SQL GUID Column

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Leon

    #1

    DataGrid and SQL GUID Column

    Hi,
    I have SQL DB table with a GUID Primary key. i used the C#
    data form wizard to create a data form (though has a typed
    dataset) with a Grid (the GUID column is not shown on the
    grid). when the user adds a new row at the end of rows in
    the grid (, types data in) and moves to another row the
    error message appears: "primary key cant be null". what
    should i do to make the system generate a new GUID for the
    primary key column in the newly added row? (the default
    value for the PK column is (newid()). but no default value
    in the dataset properties) what event or default value i
    should use?
    thank you very much in advace.
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: DataGrid and SQL GUID Column

    Leon,

    In this case, you are going to have to hook into the Grid and find out
    before the current row is changed (probably through the CellChanged event).
    Once you have that, you will have to set the column in the data set to a new
    guid value.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - nicholas.paldin o@exisconsultin g.com

    "Leon" <r_rahmaty@hotm ail.com> wrote in message
    news:05b801c354 f6$f4817a40$a30 1280a@phx.gbl.. .[color=blue]
    > Hi,
    > I have SQL DB table with a GUID Primary key. i used the C#
    > data form wizard to create a data form (though has a typed
    > dataset) with a Grid (the GUID column is not shown on the
    > grid). when the user adds a new row at the end of rows in
    > the grid (, types data in) and moves to another row the
    > error message appears: "primary key cant be null". what
    > should i do to make the system generate a new GUID for the
    > primary key column in the newly added row? (the default
    > value for the PK column is (newid()). but no default value
    > in the dataset properties) what event or default value i
    > should use?
    > thank you very much in advace.[/color]


    Comment

    Working...