Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当我单击按钮时,会显示此错误。帮我解决这个错误。我想把数据保存在两个表中_C#_Sql_Asp.net - Fatal编程技术网

C# 当我单击按钮时,会显示此错误。帮我解决这个错误。我想把数据保存在两个表中

C# 当我单击按钮时,会显示此错误。帮我解决这个错误。我想把数据保存在两个表中,c#,sql,asp.net,C#,Sql,Asp.net,子查询返回了多个值。这是不允许的,因为 子查询后面是=,!=,=或者当子查询用作 表情 我的aspx代码是 protected void txtsave_Click(object sender, EventArgs e) { try { SqlCommand cmd = new SqlCommand("Insert_MainTable", con); cmd.CommandType = CommandType.St

子查询返回了多个值。这是不允许的,因为 子查询后面是=,!=,=或者当子查询用作 表情

我的aspx代码是

protected void txtsave_Click(object sender, EventArgs e)
{
        try
        {

            SqlCommand cmd = new SqlCommand("Insert_MainTable", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Name", txtname.Text);
            cmd.Parameters.AddWithValue("@Addr", txtaddr.Text);
            cmd.Parameters.AddWithValue("@Qual", txtqual.Text);
            cmd.Parameters.AddWithValue("@Dob", txtdob.Text);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
        catch { }
    }
}
我的程序是

USE [Harish]
GO
/****** Object:  StoredProcedure [dbo].[Insert_MainTable]    Script Date: 24-12-2015 16:36:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[Insert_MainTable]


@Name varchar(50),
@Addr varchar(50),

@Qual varchar(50),
@Dob varchar(50)
as begin


insert into MainPracticeTable(Name,Addr) values(@Name,@Addr)

declare @Eid int
set @Eid=(select Id from MainPracticeTable where Name=@Name)


insert into  PracticeTable(Eid,Qual,Dob)values(@Eid,@Qual,@Dob)

end

提前谢谢。

此语句返回多行

select Id from MainPracticeTable where Name=@Name
因此,要么修复你的
where
子句,要么用
orderby
添加
top
关键字

set @Eid=(select TOP 1 Id from MainPracticeTable where Name=@Name order by somecol)


此语句返回多行

select Id from MainPracticeTable where Name=@Name
因此,要么修复你的
where
子句,要么用
orderby
添加
top
关键字

set @Eid=(select TOP 1 Id from MainPracticeTable where Name=@Name order by somecol)


@HarishSangwan-如果有帮助,您需要将其标记为答案you@HarishSangwan-如果这对您有帮助,您需要将其标记为答案