我有2张桌子.UniversityReg&登录。当大学注册到系统时,一般细节将转到UniversityReg table&登录详细信息转到登录表。使用范围标识它需要最后一个id.BUT上面提到的错误显示。
UniversityReg Table
[UniversityId] [int] IDENTITY(1,1) NOT NULL,
[Username] [varchar](50) NULL,
[Password] [varchar](50) NULL,
[UniversityName] [varchar](50) NULL,
[GovernmentRegNo] [varchar](50) NULL,
[Country] [varchar](50) NULL,
[CreatedBy] [varchar](50) NULL,
[ShortCode] [varchar](50) NULL,
登录表
[LoginID] [int] NOT NULL,
[UserName] [nvarchar](50) NOT NULL,
[Password] [nvarchar](50) NOT NULL,
[ShortCode] [nvarchar](50) NULL
SupporterReg Table
[SupporterId] [int] NOT NULL,
[SupporterName] [varchar](50) NULL,
[University] [varchar](50) NULL,
[ContactNo] [varchar](50) NULL,
[Email] [varchar](50) NULL,
[StudentLocation] [varchar](50) NULL,
[ImagePath] [varchar](50) NULL,
[ShortCode] [varchar](50) NULL,
要插入我使用以下存储过程的数据,
CREATE PROCEDURE [dbo].[UniversityReg_SP]
(
@Username varchar(50),
@Password varchar(50),
@UniversityName varchar(50) ,
@GovernmentRegNo varchar(50) ,
@Country varchar(50) ,
@CreatedBy varchar(50)
)
AS
DECLARE @LoginID int
INSERT INTO UniversityReg values(@UniversityName,@GovernmentRegNo,@Country,@CreatedBy,'UNI')
SET @LoginID = SCOPE_IDENTITY();
INSERT INTO Login values(@LoginID,@Username,@Password,'UNI')
RETURN
错误是什么?我看不到任何表错误......
答案 0 :(得分:2)
您插入UniversityReg的值太少。
N.B。这种类型的插入被认为是不好的做法 - 考虑指定你要插入的列,例如
而不是:
insert into table values(x,y,z)
执行:
insert into table (col1,col2,col3) values(x,y,z)
答案 1 :(得分:1)
您必须使用代码:
INSERT INTO UniversityReg(UniversityName,GovernmentRegNo,Country,CreatedBy,ShortCode)
values(@UniversityName,@GovernmentRegNo,@Country,@CreatedBy,'UNI')
表UniversityReg
有7列,但在插入中有5列。
答案 2 :(得分:-1)
private void btninsert_Click(object sender, EventArgs e)
{
try
{
con.Open();
cmd = new SqlCommand("insert into Empinfo values ('" + textBox1.Text + "''" + textBox2.Text + "''" + textBox3.Text + "''" + textBox4.Text + "')", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Insert the record");
cmd.Dispose();
}
catch(Exception e1)
{
MessageBox.Show("e1");
}
finally
{
con.Close();
}
}