M
Marc Pelletier
Hello,
I am trying to use the find method to locate a particular record in a
table. The code is :
object[]findTheseVals = new object[2];
findTheseVals[0] = station_ID; // an integer
findTheseVals[1] = dt; // a datetime
DataRow foundRow = dsStationDays.Tables["StationDays"].Rows.Find(
findTheseVals);
It is virtually verbatim from the help file. The StationDays table has a
primary key on an integer and datetime field combination, but I get a
[MissingPrimaryKeyException: Table doesn't have a primary key.] exception
when I execute the code. I have included the sql below that creates the
table:
CREATE TABLE [dbo].[StationDays] (
[Station_ID] [int] NOT NULL ,
[Day] [smalldatetime] NOT NULL ,
[Range] [float] NULL ,
[HighTide] [float] NULL ,
[LowTide] [float] NULL ,
[HighTime] [smalldatetime] NULL ,
... many more ...
[MoonSet] [smalldatetime] NULL ,
[MoonPhase] [float] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[StationDays] WITH NOCHECK ADD
CONSTRAINT [PK_StationDays] PRIMARY KEY CLUSTERED
(
[Station_ID],
[Day]
) ON [PRIMARY]
GO
CREATE UNIQUE INDEX [StationDay] ON [dbo].[StationDays]([Station_ID],
[Day]) ON [PRIMARY]
GO
I'm not clear if I have an sql problem, or a csharp problem, but
hopefully someone here can help me.
Thanks
Marc Pelletier
I am trying to use the find method to locate a particular record in a
table. The code is :
object[]findTheseVals = new object[2];
findTheseVals[0] = station_ID; // an integer
findTheseVals[1] = dt; // a datetime
DataRow foundRow = dsStationDays.Tables["StationDays"].Rows.Find(
findTheseVals);
It is virtually verbatim from the help file. The StationDays table has a
primary key on an integer and datetime field combination, but I get a
[MissingPrimaryKeyException: Table doesn't have a primary key.] exception
when I execute the code. I have included the sql below that creates the
table:
CREATE TABLE [dbo].[StationDays] (
[Station_ID] [int] NOT NULL ,
[Day] [smalldatetime] NOT NULL ,
[Range] [float] NULL ,
[HighTide] [float] NULL ,
[LowTide] [float] NULL ,
[HighTime] [smalldatetime] NULL ,
... many more ...
[MoonSet] [smalldatetime] NULL ,
[MoonPhase] [float] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[StationDays] WITH NOCHECK ADD
CONSTRAINT [PK_StationDays] PRIMARY KEY CLUSTERED
(
[Station_ID],
[Day]
) ON [PRIMARY]
GO
CREATE UNIQUE INDEX [StationDay] ON [dbo].[StationDays]([Station_ID],
[Day]) ON [PRIMARY]
GO
I'm not clear if I have an sql problem, or a csharp problem, but
hopefully someone here can help me.
Thanks
Marc Pelletier