eclipsed4utoo
December 14th, 2008, 11:25 AM
I am having a problem getting LINQ to do a simple insert a specific table. I get a compile error that states:
'System.Data.Linq.Table<TimeSheet.Customer>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Data.Linq.Table<TimeSheet.Customer>' could be found (are you missing a using directive or an assembly reference?)"
private void AddCustomer()
{
try
{
Customer customer = new Customer();
customer.Name = txtName.Text;
customer.Address1 = txtAddress1.Text;
customer.Address2 = txtAddress2.Text;
customer.City = txtCity.Text;
customer.State = txtState.Text;
customer.ZipCode = txtZipCode.Text;
customer.Contact = txtContactName.Text;
customer.Email = txtEmail.Text;
customer.PhoneNumber = txtPhoneNumber.Text;
db.Customers.Add(customer); //Compile error is here
db.SubmitChanges();
lblInformation.Text = "Customer Added successfully";
lblInformation.Visible = true;
timer1.Enabled = true;
}
catch
{
lblInformation.Text = "Adding customer failed.";
lblInformation.Visible = true;
timer1.Enabled = true;
}
}
here is the database table layout:
CREATE TABLE [dbo].[Customers](
[CustomerID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](255) NOT NULL,
[Address1] [varchar](255) NULL,
[Address2] [varchar](255) NULL,
[City] [varchar](50) NULL,
[State] [varchar](100) NULL,
[ZipCode] [varchar](50) NULL,
[Contact] [varchar](150) NULL,
[PhoneNumber] [varchar](15) NULL,
[Email] [varchar](50) NULL,
CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED
(
[CustomerID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Any ideas?
'System.Data.Linq.Table<TimeSheet.Customer>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Data.Linq.Table<TimeSheet.Customer>' could be found (are you missing a using directive or an assembly reference?)"
private void AddCustomer()
{
try
{
Customer customer = new Customer();
customer.Name = txtName.Text;
customer.Address1 = txtAddress1.Text;
customer.Address2 = txtAddress2.Text;
customer.City = txtCity.Text;
customer.State = txtState.Text;
customer.ZipCode = txtZipCode.Text;
customer.Contact = txtContactName.Text;
customer.Email = txtEmail.Text;
customer.PhoneNumber = txtPhoneNumber.Text;
db.Customers.Add(customer); //Compile error is here
db.SubmitChanges();
lblInformation.Text = "Customer Added successfully";
lblInformation.Visible = true;
timer1.Enabled = true;
}
catch
{
lblInformation.Text = "Adding customer failed.";
lblInformation.Visible = true;
timer1.Enabled = true;
}
}
here is the database table layout:
CREATE TABLE [dbo].[Customers](
[CustomerID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](255) NOT NULL,
[Address1] [varchar](255) NULL,
[Address2] [varchar](255) NULL,
[City] [varchar](50) NULL,
[State] [varchar](100) NULL,
[ZipCode] [varchar](50) NULL,
[Contact] [varchar](150) NULL,
[PhoneNumber] [varchar](15) NULL,
[Email] [varchar](50) NULL,
CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED
(
[CustomerID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Any ideas?