错误信息
消息 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();
}
我现在不知道该怎么做,我没有放任何重复项。
我只想更新 RTUNumber、SRTUNumber、Description 和 SDescription,同时保持我的 stationID、systemID、CCNumber、LineNumber 和 Area_ID 不变。请帮忙
更新:选择语句
SELECT * FROM RTU_ADDRESS WHERE Area_ID='IUY ' AND StationId='2' AND SystemId='5' AND CCNumber='4' AND LineNumber='6'
给我 2 个结果,但 RTUNumber 和 SRTUNumber 不同。
请帮忙