I created a stored procedure in SQL Server 2005 is supposed to insert values into a table, Customers. In Visual Studio 2008, I created a data class that represents the fields in the Customer Table. I also created a Data Access Class that accepts connects to the database to perform CRUD. I am able to fetch information from the table, perform updates and delete.
However, I have tried inserting records for days, without success. I believe the trouble is not from my VS Application! Below is the code for the Data Access Class Insert Method:
public void InsertCustomer(string customerName, string address)
{
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("CustomerInsert", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@CustomerName", customerName);
cmd.Parameters.AddWithValue("@Address", address);
try
{
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
return;
}
catch
{
conn.Close();
return;
}
}
I placed a break point in this method, and all the variables are holding exactly what i want inserted into the database. However nothing makes it into the database.
The Table definition is as follows:
CustomerID int, PK
CustomerName varchar(50)
Address varchar(50)
Below is the Stored Procedure Code:
CREATE PROCEDURE [dbo].[CustomerInsert]
(
@CustomerID int,
@CustomerName varchar(50),
@Address varchar(50)
)
AS
INSERT INTO dbo.Customer
(
CustomerID,
CustomerName,
Address
)
VALUES
(
@CustomerID,
@CustomerName,
@Address
)
Please what am i doing wrong? Someone PLEASE HELP ME!!!! Waiting.....