エラーメッセージ
メッセージ2601、レベル14、状態1、行1一意のインデックス「一意キーRTU」を持つオブジェクト「dbo.RTU_ADDRESS」に重複するキー行を挿入できません。重複するキー値は(2、5、4、6、500、610、IUY)です。ステートメントは終了されました。
テーブルのスクリプト
USE [hts]
GO
/****** Object: Table [dbo].[RTU_ADDRESS] Script Date: 03/19/2013 21:07:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[RTU_ADDRESS](
[RowNo] [int] IDENTITY(1,1) NOT NULL,
[StationId] [int] NULL,
[SystemId] [int] NULL,
[CCNumber] [int] NULL,
[LineNumber] [int] NULL,
[RTUNumber] [int] NULL,
[SRTUNumber] [int] NULL,
[Description] [char](100) NOT NULL,
[SDescription] [char](100) NOT NULL,
[Area_ID] [char](10) NOT NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
インデックス用のスクリプト
USE [hts]
GO
/****** Object: Index [Unique Key RTU] Script Date: 03/19/2013 21:08:31 ******/
CREATE UNIQUE NONCLUSTERED INDEX [Unique Key RTU] ON [dbo].[RTU_ADDRESS]
(
[StationId] ASC,
[SystemId] ASC,
[CCNumber] ASC,
[LineNumber] ASC,
[RTUNumber] ASC,
[SRTUNumber] ASC,
[Area_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
C#コード:
SqlDataAdapter sqlAdapter = null;
strSelectCmd = "SELECT RowNo FROM RTU_ADDRESS";
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = m_SqlConn;
sqlCmd.CommandText = strSelectCmd;
int i = Convert.ToInt32(sqlCmd.ExecuteScalar());
sqlAdapter = new SqlDataAdapter();
sqlAdapter.SelectCommand = sqlCmd;
strInsCmd = "UPDATE RTU_ADDRESS SET RTUNumber='" + rtunum.Text + "', SRTUNumber='" + srtunum.Text + "', Description='" + desc.Text + "', SDescription='" + sdesc.Text + "' WHERE Area_ID='" + area_ID.Text + "' AND StationId='" + station.Text + "' AND SystemId='" + sys.Text + "' AND CCNumber='" + ccnum.Text + "' AND LineNumber='" + linenum.Text + "'";
strErrorMsg = Utilities.ExecuteSQLCommand(m_SqlConn, strInsCmd);
string check = "duplicate";
bool d = check.Any(strErrorMsg.Contains);
if (d == true)
{
MessageBox.Show(" Duplicates Entries Found", "Database Insertion");
}
else if (string.IsNullOrEmpty(strErrorMsg) == false)
{
MessageBox.Show(this, "Error!Unable to Add New RTU Configurations!", "RTU Configurations error");
}
else
{
d = false;
this.Close();
}
私は今何をすべきか迷っています、私は重複を入れませんでした。
stationID、systemID、CCNumber、LineNumber、Area_IDを一定に保ちながら、RTUNumber、SRTUNumber、Description、SDescriptionを更新したいだけです。助けてください
更新:ステートメントを選択
SELECT * FROM RTU_ADDRESS WHERE Area_ID='IUY ' AND StationId='2' AND SystemId='5' AND CCNumber='4' AND LineNumber='6'
2つの結果が得られますが、RTUNumberとSRTUNumberは異なります。
助けてください