我正在尝试编写将值插入表中的过程,但值未插入表中以供参考我给出了我尝试过的代码......谁能帮助我
插入我试试这段代码
public int Visitor_Insert(visitor_Master visitor_obj, common_Class comm_obj)
{
DB_Connection();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT_VISITOR";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
cmd.Parameters.AddWithValue("@VISITOR_NAME", visitor_obj.VisitorName);
cmd.Parameters.AddWithValue("@VISITOR_CONTACT", visitor_obj.VisitorContact);
cmd.Parameters.AddWithValue("@VISITOR_ADDRESS", visitor_obj.VisitorAddress);
cmd.Parameters.AddWithValue("@VISITOR_AGE", visitor_obj.VisitorAge);
cmd.Parameters.AddWithValue("@VISITOR_VEHICLENO", visitor_obj.VisitorVehicleNO);
//cmd.Parameters.AddWithValue("@VISITOR_AGE ", visitor_obj.VisitorAge);
int i = cmd.ExecuteNonQuery();
return i;
}
对于程序,我写了这段代码
USE [VPMS]
GO
/****** Object: StoredProcedure [dbo].[INSERT_VISITOR] Script Date: 07/24/2013 16:01:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[INSERT_VISITOR]
@VISITOR_NAME NVARCHAR(30),
@VISITOR_CONTACT NVARCHAR(10),
@VISITOR_ADDRESS NVARCHAR(40),
@VISITOR_AGE NVARCHAR(2),
@VISITOR_VEHICLENO NVARCHAR(20),
@VISITOR_IMAGE IMAGE,
@VISITOR_CREATEDBY NVARCHAR(20),
@VISITOR_CREDTEDON NVARCHAR(20),
@VISITOR_MODIFIEDBY NVARCHAR(20),
@VISITOR_MODIFIEDON NVARCHAR(20)
AS
DECLARE @VISITOR_ID INT,
BEGIN
SET NOCOUNT ON;
SELECT @VISITOR_ID= MAX(Visitor_Id) FROM Visitor_Master
IF (@VISITOR_ID > 0 )
BEGIN
SET @VISITOR_ID=@VISITOR_ID+1
END
ELSE
BEGIN
SET @VISITOR_ID=10
END
INSERT INTO Visitor_Master( Visitor_Id, VisitorName, Visitor_Contact, Visitor_Address, Visitor_age,
Visitor_VehicleNo, Visitor_Image, Created_By, Created_On, Modify_By, Modify_On)
VALUES(@VISITOR_ID,@VISITOR_NAME,@VISITOR_CONTACT,@VISITOR_ADDRESS,@VISITOR_AGE,@VISITOR_VEHICLENO,@VISITOR_IMAGE,@VISITOR_CREATEDBY,
@VISITOR_CREDTEDON,@VISITOR_MODIFIEDBY,@VISITOR_MODIFIEDON)
END