问题描述
我正在使用Visual Studio 2010和SQL.I创建了Asp.Net Web应用程序。我正在使用存储过程将值传递给数据库。
在数据库中,我创建了一个名为project的表,其中包含一些字段,其中两个字段数据类型为 MONEY
,列名为expectedtotalcost和actualtotalcost
ASP.NET代码:
Hi,i am using Visual studio 2010 and SQL.I have created Asp.Net web application.I am using stored procedure to pass values to database.
In database,i have created a table called project which contains some fields in which two of the field data type is MONEY
and column name is "expectedtotalcost" and actualtotalcost"
ASP.NET code:
public void InsertProjectBasicInfo( string expectedtotalcost, string actualtotalcost)
{
SqlConnection sqlcon;
SqlCommand sqlcmd;
double money;
try
{
sqlconnstring = ConfigurationManager.ConnectionStrings["CONERP"].ConnectionString;
sqlcon = new SqlConnection(sqlconnstring);
sqlcon.Open();
sqlcmd = new SqlCommand("CreateNewProject", sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add("@expectedtotalcost", SqlDbType.Money).Value =
Double.TryParse(expectedtotalcost, out money);
sqlcmd.Parameters.Add("@actualtotalcost", SqlDbType.Money).Value =
Double.TryParse(actualtotalcost, out money);
sqlcmd.ExecuteNonQuery();
sqlcmd.Dispose();
sqlcon.Close();
}
catch (SqlException sqlerr)
{
}
}
InsertProjectBasicInfo(txtExpectedProjectCost.Text.Trim(), txtActualProjectCost.Text.Trim());
SQL查询:
SQL Query:
USE [COERP]
GO
/****** Object: StoredProcedure [dbo].[CreateNewProject] Script Date: 10/15/2013 10:43:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[CreateNewProject](
@expectedtotalcost money ,
@actualtotalcost money)
as
begin
insert into Project values(@expectedtotalcost,
@actualtotalcost)
end
没有错误信息.. ??值总是1.0。如果你按步骤格式提供答案,将会有所帮助。
谢谢
-Sid -
No error message..?? the value is always "1.0".It will b helpful if you provide the answer in step by step format.
Thanks
-Sid-
推荐答案
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.AddWithValue("@expectedtotalcost", expectedtotalcost);
sqlcmd.Parameters.AddWithValue("@actualtotalcost", actualtotalcost);
sqlcmd.ExecuteNonQuery();
in palace of
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add("@expectedtotalcost", SqlDbType.Money).Value =
Double.TryParse(expectedtotalcost, out money);
sqlcmd.Parameters.Add("@actualtotalcost", SqlDbType.Money).Value =
Double.TryParse(actualtotalcost, out money);
sqlcmd.ExecuteNonQuery();
这篇关于如何使用存储过程将(asp.net项目)文本值传递给SQL中的money数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!