我有一张桌子
CREATE TABLE [dbo].[DealerInfo](
[DealerName] [nvarchar](100) NULL,
[Address] [nvarchar](100) NULL,
[City] [nvarchar](100) NULL,
[County] [nvarchar](100) NULL,
[Fax] [nvarchar](50) NULL,
[CompanyWebSite] [nvarchar](max) NULL,
[EmailAddress] [nvarchar](100) NULL,
[Currency] [nvarchar](20) NULL,
[LicenceID] [int] NULL,
[TaxRegistration] [int] NULL,
[Phone] [nvarchar](50) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
还有一个问题,当我尝试插入货币值时,它报告它需要一个整数值
我用存储过程插入值
ALTER PROCEDURE [dbo].[DealerInformation]
-- Add the parameters for the stored procedure here
@DealerName nvarchar(100),
@Address nvarchar(100),
@City nvarchar (100),
@County nvarchar (100),
@Phone nvarchar (100),
@Fax nvarchar(50),
@CompanyWebSite nvarchar (100),
@EmailAddress nvarchar(Max),
@Currency nvarchar(20),
@LicenceID int,
@TaxRegistration int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Insert into DealerInfo values (@DealerName, @Address, @City, @County, @Phone, @Fax, @CompanyWebSite,@EmailAddress,@Currency,@LicenceID,@TaxRegistration)
货币应该是一个字符串值,如美元、加元、欧元等
当我执行存储过程时,这是我得到的错误
Msg 245, Level 16, State 1, Procedure DealerInformation, Line 26 [Batch Start Line 2]
Conversion failed when converting the nvarchar value 'USD' to data type int.
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=CarDealership;Integrated Security=True") )
{
conn.Open();
SqlCommand cmd = new SqlCommand("DealerInformation", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("DealerName", dealership.DealershipName);
cmd.Parameters.AddWithValue("Address", dealership.Address);
cmd.Parameters.AddWithValue("City", dealership.City);
cmd.Parameters.AddWithValue("County", dealership.Country);
cmd.Parameters.AddWithValue("Phone", dealership.Telephone);
cmd.Parameters.AddWithValue("Fax", dealership.Fax);
cmd.Parameters.AddWithValue("CompanyWebSite", dealership.CompanyWebSite);
cmd.Parameters.AddWithValue("EmailAddress", dealership.Email);
cmd.Parameters.AddWithValue("Currency", dealership.Currency); //The currency is string type
cmd.Parameters.AddWithValue("LicenceID", dealership.LicenceID);
cmd.Parameters.AddWithValue("TaxRegistration", dealership.TaxRegistration);
int RowsAffected = cmd.ExecuteNonQuery();
return RowsAffected;
}