You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET. The application connects to a Microsoft SQL Server 2005 database.
You write the following DDL statement.
CREATE TABLE [dbo].[tblTest](
[C1] [int] IDENTITY(1,1) NOT NULL,
[C2] [char](4) NULL,
[C3] NUMERIC(1,1) NOT NULL,
[C4] AS (C1*C3)
) ON [PRIMARY]
The application contains a method named update. The update method uses the following code segment.
SqlDataAdapter da = new SqlDataAdapter(“SELECT * FROM tblTest”,sc);
da.UpdateCommand = new SqlCommand(“UPDATE tblTest SET C2 = @C2, c3 = @C3, C4 = @C4 WHERE C1 = @C1”, sc);
da.UpdateCommand.Parameters.Add(“@C1”, SqlDbType.Int, 4, “C1”);
SqlParameter prm1 = new SqlParameter(“@C2”, SqlDbType.Char, 4);
prm1.SourceColumn = “C2”;
da.UpdateCommand.Parameters.Add(prm1);
SqlParameter prm2 = new SqlParameter(“@C3”, SqlDbType.Decimal,4);
prm2.SourceColumn = “C3”;
da.UpdateCommand.Parameters.Add(prm2);
SqlParameter prm3 = new SqlParameter(“@C4”, SqlDbType.Char, 4);
prm3.SourceColumn = “C4”;
da.UpdateCommand.Parameters.Add(prm3);
When you execute the method, a SqlException exception is thrown.You need to ensure that the method is successfully executed.
What should you do?
A.
Change the SqlDbType parameter to Money in column C4.
B.
Change the SqlDbType parameter to Decimal in column C4.
C.
Remove column C4 and its associated parameters from the UPDATE statement.
D.
Remove column C3 and its associated parameters from the UPDATE statement.