从sql表返回值的问题 [英] Issues returning values from sql table

查看:47
本文介绍了从sql表返回值的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序应该采用十进制输入,推送到存储过程并返回一个char值以供在应用程序中使用。



对于某些人来说原因,我的所有其他存储过程似乎工作正常,但是这个特定的SP根本不起作用。



最初,输入的形式是下拉列表,但列表中的值不正确。



例如:SQL表中的0.975会在下拉列表中显示为1.000.

1.025不知何故变为1.050。 1.075变成了2.000



所以我抛弃了下拉列表,转而使用文本框。我仍然没有收到正确的退货值。实际上,我根本没有得到任何价值。



这是我的代码:



申请表页面

I have an application that is supposed to take a decimal input, push into a stored procedure and return a char value for use in the application.

For some reason, all of my other stored procedures seem to be working fine, however this one particular SP is not working at all.

Originally, the input was in the form of a dropdown list, however the values in the list were incorrect.

For example: 0.975 in the SQL table would show up as 1.000 in the drop down list.
1.025 somehow became 1.050. 1.075 became 2.000

So I tossed out the drop down list in favor of a text box. I still am not receiving proper return values. Actually, I am not getting any values back at all.

Here is my code:

Application Page

<asp:Label ID="Label2" runat="server" Text="Select RZD: "></asp:Label>
     <asp:TextBox ID="rzdTB" runat="server"></asp:TextBox>
<asp:Label ID="rzdFSLabel" runat="server" Text="Label"></asp:Label>





Code Behind



Code Behind

fileNameGenerator fNG = new fileNameGenerator();
fNG.rzd = Convert.ToDouble(rzdTB.Text);
fNG.fileGenerator();
rzdFSLabel.Text = fNG.rzdfsOUT;

Label13.Text = fNG.bcfsOUT + fNG.rzdfsOUT + fNG.anglefsOUT + fNG.powerfsOUT;
lBO.fileName = fNG.bcfsOUT + fNG.rzdfsOUT + fNG.anglefsOUT + fNG.powerfsOUT;





fileNameGenerator



fileNameGenerator

//declare rzd variable - convert to double
//declare rzdSymbol as the output
c2.Parameters.AddWithValue("@rzd", SqlDbType.Float).Value =rzd;
SqlParameter rzdSymbol = new SqlParameter("@rzdSymbol", SqlDbType.VarChar);
rzdSymbol.Size = 2;
rzdSymbol.Direction = ParameterDirection.Output;
c2.Parameters.Add(rzdSymbol);

//open the connection string and execute the sproc
conn.Open();
c1.ExecuteNonQuery();
c2.ExecuteNonQuery();
c3.ExecuteNonQuery();
c4.ExecuteNonQuery();
conn.Close();

bcfsOUT = c1.Parameters["@bcFS"].Value.ToString();

//string sdfsOUT to label2
rzdfsOUT = c2.Parameters["@rzdSymbol"].Value.ToString();





存储过程



Stored Procedure

ALTER PROCEDURE dbo.getRZDSymbol
	(
		@rzd decimal(10,5),
		@rzdSymbol varchar(2) OUTPUT
	)
AS
	SET NOCOUNT ON
	SELECT @rzdSymbol = rzdSymbol
	FROM fileSymbolTable
	WHERE rzd = @rzd





谢谢f或者帮助。



thank you for the help.

推荐答案

在调试时仔细查看了c2参数。我一直看到FLOAT作为rzd数据类型。这似乎很奇怪所以我开始调查我从哪里提取数据。更令人困惑的是,我的本地计算机上有两个数据库,网络上的开发服务器上有一个数据库。我相信我仍然挂在本地机器上,但它转向我从网络数据库中拉出来。



将表放在网络上,重新导入本地机器和BAM!



突然间它起作用了。想象一下......
had a deep look at the c2 parameter while debugging. I kept seeing "FLOAT" as the rzd datatype. That seemed rather odd so I began investigating where exactly I was pulling data from. TO make matters more confusing, I have two databases on my local machine and one on a development server on our network. I believed I was still hooked into the local machine, but it turns I was pulling from the networked db.

Drop the table on the network, re-imported from the local machine and BAM!

All of a sudden it works. Imagine that...


这篇关于从sql表返回值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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