my first class is CustomerDal.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
public class CustomerDal
{
public CustomerDal()
{
}
public int insert(string customer_id,string first_name,string last_name)
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["learnConnectionString"].ConnectionString);
string s1 = "insert into customer(customer_id,first_name,last_name) values(@customer_id,@first_name,@last_name) ";
SqlCommand cmd = new SqlCommand(s1,conn);
cmd.CommandType = CommandType.Text;
try
{
cmd.Parameters.Add(new SqlParameter("customer_id", System.Data.SqlDbType.Int, 4));
cmd.Parameters["@customer_id"].Direction = System.Data.ParameterDirection.Input;
cmd.Parameters["@customer_id"].Size = 25;
cmd.Parameters["@customer_id"].Value = customer_id;
cmd.Parameters.Add(new SqlParameter("first_name", SqlDbType.VarChar));
cmd.Parameters["@first_name"].Direction = ParameterDirection.Input;
cmd.Parameters["@first_name"].Size = 25;
cmd.Parameters["@first_name"].Value = first_name;
cmd.Parameters.Add(new SqlParameter("last_name", SqlDbType.VarChar));
cmd.Parameters["@last_name"].Direction = ParameterDirection.Input;
cmd.Parameters["@last_name"].Size = 25;
cmd.Parameters["@last_name"].Value = last_name;
conn.Open();
return cmd.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
conn.Close();
cmd.Dispose();
conn.Dispose();
}
}
}
my second class ic CustomerBal.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class CustomerBal
{
public CustomerBal()
{
}
public int insert(string customer_id, string first_name, string last_name)
{
CustomerDal cdal = new CustomerDal();
try
{
return cdal.insert(customer_id, first_name, last_name);
}
catch
{
throw;
}
finally
{
cdal=null;
}
}
}
and my default.aspx page is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
CustomerBal Cbal = new CustomerBal();
try
{
if (Cbal.insert(TextBox1.Text, TextBox2.Text, TextBox3.Text) > 0)
{
Label1.Text = "Record Inserted Successfully";
}
else
{
Label1.Text = "Record not Inserted";
}
}
catch(Exception ex)
{
Label1.Text = ex.Message;
}
finally
{
Cbal = null;
}
}
}
and when i run this program than the error is coming
Error:An SqlParameter with ParameterName '@customer_id' is not contained by this SqlParameterCollection.
please give me solution......