简体   繁体   English

从SQL Server表返回值的问题

[英]Issues returning values from SQL Server table

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. 我有一个应用程序,该应用程序应该采用十进制输入,将其推入存储过程并返回一个char值以供该应用程序使用。

For some reason, all of my other stored procedures seem to be working fine, however this one particular stored procedure 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 Server table would show up as 1.000 in the drop down list. 例如:SQL Server表中的0.975在下拉列表中将显示为1.000。 1.025 somehow became 1.050. 1.025以某种方式变为1.050。 1.075 became 2.000 1.075变成了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: 这是我的代码:

Form: 形成:

<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: 后面的代码:

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()

//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 stored procedures
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

I feel foolish, but the answer was rather simple. 我觉得很愚蠢,但是答案很简单。

I had a deep look at the c2 parameter while debugging. 在调试时,我对c2参数进行了深入研究。 I kept seeing "FLOAT" as the rzd datatype. 我一直看到“ FLOAT”作为rzd数据类型。 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! 将表拖放到网络上,从本地计算机和BAM重新导入!

All of a sudden it works. 突然间它起作用了。 Imagine that... 想象一下...

Very sorry, but thank you all for the help. 非常抱歉,谢谢大家的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM