如何使用sql程序和asp.net查找特定数据 [英] how to findout particular data using sql procedure and asp.net

查看:117
本文介绍了如何使用sql程序和asp.net查找特定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

i有一个网络应用程序我输入了一个数据,它会检查是否已存在或不存在,在数据不存在之后它会存储在

sql server2008表它会存在给定的消息

已经存在数据,我写了程序但是程序是

不工作存在的数据也存储在下面给出了代码

hello ,
i have one web application i am entered one data it will check whether
it has existed or not ,after the data is not existed it will stored in
sql server2008 table it will existed given the message like that
already data existed ,i am writed the programme but the programme is
not working the data existed it also stored code is given below

SqlConnection con = new SqlConnection("Data Source=NSYS1\\SQLEXPRESS;Initial Catalog=agfl;connect timeout=30;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("SVF", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@sno",TextBox1.Text);
            cmd.Parameters.AddWithValue("@rdate",TextBox6.Text );
            cmd.Parameters.AddWithValue("@acno",TextBox2.Text );
            cmd.Parameters.AddWithValue("@name",TextBox7.Text );
            cmd.Parameters.AddWithValue("@vno",TextBox4.Text );
            cmd.Parameters.AddWithValue("@amt",TextBox8.Text );
            cmd.Parameters.AddWithValue("@edate",TextBox5.Text );
            cmd.Parameters.AddWithValue("@chno",TextBox9.Text);
            cmd.Parameters.Add("@ERROR", SqlDbType.VarChar, 100);
            cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
            cmd.ExecuteNonQuery();
            string message = (string)cmd.Parameters["@ERROR"].Value;
            con.Close();
            Label17.Text = message;



sql server proceduure


sql server proceduure

USE [agfl]
GO
/****** Object:  StoredProcedure [dbo].[SVF]    Script Date: 02/18/2014 11:20:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SVF]
@sno nchar(5),
@rdate datetime,
@acno nchar(14),
@name nchar(14),
@vno nchar(20),
@amt numeric(16,2),
@edate date,
@chno nchar(14),
@ERROR VARCHAR(100) OUT

AS 
BEGIN
SET NOCOUNT ON;
IF  EXISTS(SELECT * FROM stf WHERE acno=@acno)
	BEGIN
		SET @ERROR='Already Exists'	
		
	END
ELSE
	BEGIN
		INSERT INTO stf(sno,rdate,acno,name,vno,amt,edate,chno) 
		VALUES
		(@sno,@rdate,@acno,@name,@vno,@amt,@edate,@chno)
	
		SET @ERROR='Registered Successfully'
		
	END
END

推荐答案

您好Raghu,



我想知道以下事实:



在您的程序中,您在消息字段中获得的内容即label17.text?



我认为根据您的问题描述,您的SP始终将消息显示为已成功注册 !!!虽然它存在与否?

是吗?或其他任何东西?



或者更好的方法如果你使用SQL Server 2008,请在SP中使用merge语句。

并查看这些东西。



温馨的问候,

编码。
Hi Raghu,

I would like to know the below facts:

Within your program what you are getting in your message field i.e. label17.text?

I think as per your question description, your SP always gives the message as "Registered successfully"!!! though it exist or not?
Is it? or any thing else?

Or better way if you are using SQL server 2008, go with merge statement in SP.
And check out the things.

Warm Regards,
Coder.


这篇关于如何使用sql程序和asp.net查找特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆