178k views
3 votes
What of the followings is correct for creating a command object with the connection con?

[A] SqlCommand Cmd = con.SetSqlCommand("Select * From Student");
[B] SqlCommand Cmd = con.GetSqlCommand("Select * From Student");
[C] SqlCommand Cmd = new SqlCommand(con,"Select * From Student");
[D] SqlCommand Cmd = new SqlCommand("Select * From Student", con);

1 Answer

2 votes

Final answer:

The correct way to create a SqlCommand object with a connection object 'con' is 'SqlCommand Cmd = new SqlCommand("Select * From Student", con);', as it properly associates a SQL command with a connection in ADO.NET.

Step-by-step explanation:

The correct way to create a SqlCommand object with the connection con is: SqlCommand Cmd = new SqlCommand("Select * From Student", con); The correct way to create a SqlCommand object with a connection object 'con' is 'SqlCommand Cmd = new SqlCommand("Select * From Student", con);', as it properly associates a SQL command with a connection in ADO.NET.

This line creates a new instance of the SqlCommand class, passing in the SQL query "Select * From Student" as the first parameter, and the existing connection object con as the second parameter. This is how you associate a command with a connection in ADO.NET, which is used for accessing databases in the .NET framework.

User Dubek
by
7.4k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.