my question is
can we insert a record in view.using c# application..
if yes then how can i insert a record in view..
or if i insert a record in view..thn it can affect a real table??
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Feb 13, 2013, 1:43 AM
hi,
yes, your view defination is as simple as table, i means to say your view defination is containing only single table then if you add value in view , your table automatically updated.
Insert/Update process is same as just like normal table.
Example
table defination and view defination
GO
CREATE TABLE [dbo].[EmployeeDetails](
[EmployeeID] [int] IDENTITY(1,1) NOT NULL,
[EmployeeCode] [varchar](10) NULL,
[EmployeeName] [varchar](50) NULL,
[DepartmentCode] [varchar](10) NULL,
[LocationCode] [varchar](10) NULL,
[salary] [int] NULL
) ON [PRIMARY]
GO
CREATE VIEW vwEmployeeDetails
AS
SELECT E.EmployeeCode,E.EmployeeName,DepartmentCode
FROM EmployeeDetails E
C# Code.
using (SqlConnection connection = new SqlConnection(connstringstring))
{
connection.Open();
SqlCommand addSite = new SqlCommand("INSERT INTO vwEmployeeDetails (EmployeeCode,EmployeeName,DepartmentCode)"+
"VALUES ('E0001','Jignesh','ASP')", connection);
addSite.ExecuteNonQuery();
connection.Close();
}
hope this will help you.