You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET.
You write the following code segment. (Line numbers are included for reference only.)
01 private void GetRecords(SqlDataAdapter da, DataTable table) {
02
03 try {
04 da.Fill(table);
05 }
06 catch (SqlException exp) {
07
08 }
09 finally {
10
11 }
12 }
The da.SelectCommand.CommandText property is set to a stored procedure. The stored procedure declares a variable named @msg.
For each record that contains a bad shipping address, the stored procedure performs the following tasks:
It sets @msg with the id of the record.
It raises an error for the record.
The error raised is as shown in the following text: RaiseError(@msg, 10, 1)
You need to ensure that all valid records are retrieved even if invalid records are present. You also need to ensure that a list item is added to the lstResults list box for each invalid record.
What should you do?
A.
Insert the following code segment at line 07.
foreach (SqlError error in exp.Errors)
{
lstResult.Items.Add(exp.Message);
}
B.
Insert the following code segment at line 10.
foreach (DataRow row in table.Rows)
{
if (row.HasErrors)
{
lstResult.Items.Add(row.RowError);
}
}
C.
Insert the following code segment at line 02.
SqlNotificationRequest notices = new SqlNotificationRequest();
da.SelectCommand.Notification = notices;
Insert the following line of code at line 10.
lstResult.Items.Add(notices.UserData);
D.
Insert the following code segment at line 02.
da.SelectCommand.Connection.InfoMessage += new SqlInfoMessageEventHandler(Connection_InfoMessage);
Insert the following code segment at line 13.
private void Connection_InfoMessage(object sender, SqlInfoMessageEventArgs e)
{
lstResult.Items.Add(e.Message);
}