在c#asp.net中找不到表0
在上面显示的错误“找不到表0” 当我输入无效id时,它需要显示“id不存在” 我可以知道我的密码有什么错误吗 存储过程:在c#asp.net中找不到表0,c#,C#,在上面显示的错误“找不到表0” 当我输入无效id时,它需要显示“id不存在” 我可以知道我的密码有什么错误吗 存储过程: if (ds.Tables[0].Rows.Count > 0) { txtid.Text = ds.Tables[0].Rows[0]["id"].ToString(); txttamil.Text = ds.Tables[0
if (ds.Tables[0].Rows.Count > 0)
{
txtid.Text = ds.Tables[0].Rows[0]["id"].ToString();
txttamil.Text = ds.Tables[0].Rows[0]["Tamil"].ToString();
txtenglish.Text = ds.Tables[0].Rows[0]["English"].ToString();
txtmaths.Text = ds.Tables[0].Rows[0]["Maths"].ToString();
txtscience.Text = ds.Tables[0].Rows[0]["Science"].ToString();
txtsocialscience.Text = ds.Tables[0].Rows[0]["SocialScience"].ToString();
}
}
任何帮助都将不胜感激。
谢谢,如果id不存在,您的SP不会返回任何表格数据。请尝试将其更改为
ALTER PROCEDURE sp_studentresult
(
@id int,
@output varchar(50) output,
@id_student varchar(50)
)
AS
IF EXISTS (SELECT * FROM student WHERE id=@id_student)
BEGIN
SELECT * from studentresult where id_student=@id
END
ELSE
BEGIN
SET @output='Doesn not EXIST'
End
用逻辑使sp复杂化是没有意义的 为什么不检查查询是否返回了任何数据
IF NOT EXISTS (SELECT * FROM student WHERE id=@id_student)
BEGIN
SET @output='Does not EXIST'
END
SELECT * from studentresult where id_student=@id
还有一个更简单的sp,如果找不到任何内容,它将返回一个空表
if (ds.Tables[0].Rows.Count > 0)
{
txtid.Text = ds.Tables[0].Rows[0]["id"].ToString();
txttamil.Text = ds.Tables[0].Rows[0]["Tamil"].ToString();
txtenglish.Text = ds.Tables[0].Rows[0]["English"].ToString();
txtmaths.Text = ds.Tables[0].Rows[0]["Maths"].ToString();
txtscience.Text = ds.Tables[0].Rows[0]["Science"].ToString();
txtsocialscience.Text = ds.Tables[0].Rows[0]["SocialScience"].ToString();
}
else
{
// Whatever you want to do if no row is found
}
你好当我输入无效id时,它显示id存在。。但在id无效并输入标记后,它显示已更新。我有页面搜索按钮,下面我添加了文本框,以便在输入有效id时进行更新。。所以当我输入无效的id。。它不应显示文本框。。thanks@Rani您是否注意到我将
存在
更改为不存在
?
ALTER PROCEDURE sp_studentresult
(
@id int
)
AS
-- I have removed the extra id column as not sure why you use it
SELECT * from studentresult where id_student=@id